Long time listener, first time caller...
My table structure is as follows:
equip_items
--------------
id (pk)
equip_type_id (fk to equip_types)
site_id (fk to sites)
equip_status_id (fk to equip_status)
name
(equip_type_id, site_id, name) is a composite unique key constraint in the db. I have implemented a callback on the name field that deals with grocery_CRUD validation of the unique constraint - taking into account either editing existing or adding new equip_items.
function unique_equip_item_check($str, $edited_equip_item_id){
$var = $this->Equip_Item_model->is_unique_except($edited_equip_item_id,$this->input->post('site_id'),$this->input->post('equip_type_id'),$this->input->post('name'));
if ($var == FALSE) {
$s = 'You already have an equipment item of this type with this name.';
$this->form_validation->set_message('unique_equip_item_check', $s);
return FALSE;
} else {
return TRUE;
}
}
I have the site_id and equip_type_id set as hidden fields as I do not want the user to change these - no problem.
$crud->field_type('site_id', 'hidden', $site_id);
$crud->field_type('equip_status_id', 'hidden', iQS_EqStatus_InUse);
When users add an equip_item I want them to be able to select the equip_type from a list of types - No problem, this is default grocery_CRUD behaviour.
$crud->add_fields('equip_status_id', 'site_id', 'equip_type_id', 'name');
When users edit an equip_item I don't want the user to be able to edit the equip_type. I figured no problem I can just set the edit_fields to exclude equip_type_id:
$crud->edit_fields('equip_status_id', 'site_id', 'name', 'barcode_no');
[b]BUT[/b] this plays havoc with my validation callback because the value of the equip_type_id field is nowhere on the edit form and it is obviously needed by my validation routine.
So I need to have the equip_type_id field visible and acting normal when adding a new record but hidden when editing a record.
I've tried this hack of all hacks <yuck!>:
if ($this->uri->segment(4)!= FALSE){$crud->field_type('equip_type_id', 'hidden');}
My theory was that "$this->uri->segment(4)" only give a false result if adding a new record, but it does not work.
Any suggestions?