⚠ 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 'do nothing' after a callback_edit_field



Dave

Dave
  • profile picture
  • Member

Posted 16 January 2016 - 10:20 AM

Hi.

 

I am trying to use the callback_edit_field function to conditionally make some fields read-only. My code works correctly when a field needs to be made read-only, but not when the field needs to remain editable.

 

My code is like this:

 

$this->grocery_crud->callback_edit_field('my-text-field',array($this,'make_field_readonly'));

$this->grocery_crud->callback_edit_field('my-drop-down-list-field',array($this,'make_field_readonly'));

 

function make_field_readonly($value, $primary_key) {
 
(... run some SQL and, based on the result, set $make_read_only to TRUE or FALSE ...)
 
if ($make_read_only) {
   return "$value"; // Display the field value as read-only text
}
else {
   // Do nothing - Leave the field as editable, e.g. as a text box or drop-down list
}
 
}

 

With this code, when the field is not made read-only (else { // do nothing } ) , the field is rendered as blank on the edit form. Is there a way for the callback_edit_field function to 'do nothing', i.e. making the fields appear exactly as they would have done if the callback_edit_field function was not used?

 

Thanks!


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 19 January 2016 - 22:11 PM

Hi there

 

Well when you do a callback, GC totally accepts your responsibility to generate the output for the same. It wont render in you have a callback registered. Hence if you wish to have an edit functionality in the field, you have to return the field for sure. You may generate the code for returning the field output or else - as you require, you may actually alter the library code to check if there is no output then let the library generate the same for you.

 

Happy GCing :)


Dave

Dave
  • profile picture
  • Member

Posted 19 January 2016 - 23:39 PM

Thanks for explaining that Amit.