⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

unable to insert (add) new item with callback_field



Nitin Thokare

Nitin Thokare
  • profile picture
  • Member

Posted 10 June 2014 - 10:55 AM

 
I have following controller functions:
 
function rfq_items(){
  $crud->columns('ItemId','Quantity','Remark');
  $crud->fields('BillId','ItemId','Quantity','Remark');

  $crud->display_as('ItemId','Item Id');
  $crud->display_as('BillId','RFQ Id');

  $crud->field_type('BillId','readonly');
  $crud->field_type('Quantity','integer');
  $crud->field_type('Remark','text');

  $crud->callback_field('BillId',array($this,'callback_field_bill_id'));

  $crud->set_relation('ItemId', 'item', '{id}-{name}');
  $crud->required_fields('BillId','ItemId','Quantity','Rate');
}




function callback_field_bill_id($value = '', $primary_key = null){
  $val = $this->uri->segment(3);
  return '<input id="field-BillId" name="BillId" type="text" value="'.$val.'" maxlength="50" style="width:462px" readonly>';
}

When I try to add new item, the add_new page opens as shown in attached image (note the auto-filled value in "RFQ Id" field). Now when I try to save the data, it gives me error in popup: "An error has occurred on insert."

 

Can anybody help to sort out the mistake in above code?

 

 


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 10 June 2014 - 18:21 PM

First question,

 

dose billID exists in the table? If not you need to manage your own insert method.. or remove the field that dose not exists b4 inserting the row

 

Secondly to make sure what is the issue / error - i will recommend u look in firebug .. in the console as what is the error - there it will have a registered post call to insert method on the CI function call ... and the output / result will display u what was the error - where was the error.