I got a set_relation (dropdown) not marked as required (*) in my form, but when hit the SAVE button, the SQL trow an error because the field is in the QUERY. (the red ones)
SQL: INSERT INTO "trafo" ("descripciontrafo", "tag", "[color=#ff0000]id_alimentador[/color]", "idtrafonet", "direccion", "idregion", "idcomuna", "lat", "lng", "voltaje_nominal", "kva", "serie", "tap", "fabricante") VALUES ('Transf-IDVIRT67', 'TRFVIRTUAL', '1', [color=#ff0000]''[/color], 'calle 3, 4', '13', '13106', '-123456', '-132456', '100', '100', 'SVC1234', '3', 'Schaffner');
as it has not required it shouldn't be on the query
$crud->display_as("idtrafonet","Equipo Trafonet");
$crud->set_relation('idtrafonet','trafonet','serial');
$crud->required_fields('descripciontrafo','tag','id_alimentador','direccion','idregion','idcomuna','lat','lng','voltaje_nominal','kva','tap');
[attachment=206:form.jpg]
any idea?
set_relation not marked as required not working
Started by jcasanova, 21 June 2012 - 14:25 PM
- Single Page
Posted 21 June 2012 - 14:25 PM
Posted 21 June 2012 - 22:48 PM
You can simply have a callback_before_insert and a callback_before_update like this:
and
This is the normal way that grocery CRUD update and insert, unless you have the id_alimentador allowed from the database to be NULL. Then you will simply have the [color=#ff0000]''[/color] to [i][color=#ff0000]NULL[/color][/i]
$crud->callback_before_insert(array($this,'remove_id_alimentador'));
$crud->callback_before_update(array($this,'remove_id_alimentador'));
and
public function remove_id_alimentador($post_array)
{
unset($post_array['id_alimentador']);
return $post_array;
}
This is the normal way that grocery CRUD update and insert, unless you have the id_alimentador allowed from the database to be NULL. Then you will simply have the [color=#ff0000]''[/color] to [i][color=#ff0000]NULL[/color][/i]