⚠ 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

How to autogenerate value and show in Add form as readonly field



thewebdepot
  • profile picture
  • Member

Posted 12 March 2012 - 10:51 AM

Hi

We have a Employee Table and we want to auto-generate the Employee Code and show it in the add form as read-only in the Employee Code field

Kindly can you guide us how we can achieve this in grocery

Thanks

Kapil Arora

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 12 April 2012 - 17:42 PM

The readonly fields are not yet included to grocery CRUD but you can use a simple callback for this, for example:


function example_callback_edit_field(){
$crud = new grocery_CRUD();

$crud->set_table('offices');
$crud->set_subject('Office');
$crud->required_fields('city');
$crud->columns('city','country','phone','addressLine1','postalCode');

$crud->callback_edit_field('phone',array($this,'example_callback_1'));

$output = $crud->render();

$this->_example_output($output);
}

function example_callback_1($value, $primary_key)
{
return "<b>".$value."</b>";
}

psimons
  • profile picture
  • Member

Posted 22 April 2012 - 14:02 PM

Hi,
This seems not to work if you use a relation as in i.e. company_id => company_name

Kind Regards, Simons

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 22 April 2012 - 15:14 PM

Yes this is a known issue and I will try to fix it for the next version. For now you can just use this work around: /topic/254-set-relation-breaks-processing-of-field-with-same-name-returned/page__p__982#entry982

psimons
  • profile picture
  • Member

Posted 22 April 2012 - 19:09 PM

Hi,

Thanks for that link. I ended up using hidden fields, since the fields in question are foreign keys whih should not be edited in the given situation. So now the add and edit works.

I have actually coded most of the vital parts of the project backend in ~200 lines of code. This tool really rocks!

I found a kind of workaround for master detail: add_action ;)

Best Regards, PsimonS