Jump to content


throws an error if unique field is empty on edit

edit unique field

  • Please log in to reply
5 replies to this topic

#1 Tomexsans

Tomexsans

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 08 May 2014 - 08:19 AM

I found this error i don't know if it is a bug or something, But if you try to add a column in unique_fields() and if you edit it, it will throw an error if that field is empty. Saying that 

 

"The field name doesn't exist in the database. ".
"Please use the unique fields only for fields ".
"that exist in the database"

 

Question why is this line https://github.com/s...y_CRUD.php#L805

Checking for the unique_fields() value rather than checking the availability of that column? what if i have unique fields that are default no data? i have been surfing for a day now and can't seem to find any answers, so i created mine , if anyone have a better answer let me know.

 

On line 805/ libraries/grocery_CRUD.php

$database_columns = array_keys((array)$row);
if(!in_array($field_name,$database_columns))
{
    throw new Exception("The field name doesn't exist in the database. ".
                         "Please use the unique fields only for fields ".
                        "that exist in the database");
}

$previous_field_name_value = $row->$field_name;

if($previous_field_name_value != $field_name_value)
{
    $form_validation->set_rules( $field_name,
                                 $field_types[$field_name]->display_as,
                                 'is_unique['.$this->basic_db_table.'.'.$field_name.']');
    $form_validation_check = true;
}


#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 08 May 2014 - 05:56 PM

well 1 question why u trying to set the table name along with the field name cuz wht it is going to do is automatically set it agains the table.. so i will recommend u doing it simply by setting the field name.. not table.fieldname



#3 Tomexsans

Tomexsans

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 11 May 2014 - 09:12 AM

Funny you said that, but i did not put any table on my field, how did you come up with that? the main problem here is that it returns an error if the unique field is empty on the first place.  My table is populated before i use GC and when i tried to add a certain a column in unique_fields it throws an error if i edit that row. and that column has no data in it.

 

As you can see i included a link that checks not the column exists but if the value of that column exist.



#4 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 12 May 2014 - 01:09 PM

$form_validation->set_rules( $field_name,
                                 $field_types[$field_name]->display_as,
                                 'is_unique['.$this->basic_db_table.'.'.$field_name.']');

This code of your above - check yourself - what you believe it is going to try and check.. just the field name or <table>.<field> name?



#5 Tomexsans

Tomexsans

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 13 May 2014 - 08:14 AM

You do not understand my point, that code is doing great on what it does, im stressing out that on line 805 why does it have to check if the column is empty. what if i have a unique column and the default is NULL. Nevermind.



#6 jinbatsu

jinbatsu

    Member

  • Members
  • PipPip
  • 23 posts

Posted 12 August 2018 - 09:00 PM

You do not understand my point, that code is doing great on what it does, im stressing out that on line 805 why does it have to check if the column is empty. what if i have a unique column and the default is NULL. Nevermind.

 

Thank You for this fix, it is 4 year old post I know, but this work if we have default NULL on unique field as you said, thanks!







Also tagged with one or more of these keywords: edit, unique field

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users