⚠ 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

Change field as "disabled" when editing row..



Charles A.

Charles A.
  • profile picture
  • Member

Posted 16 July 2013 - 22:37 PM

Hi, is there any way to show the values (but like disabled="disabled")... Only when editing.. ?? For example, i have

  • Car_Model (combobox)
  • Car_Color (combobox)
  • Observations (free text)

Following the given example, when I add, i have to complete all the data, but when I edit, I just want to edit OBSERVATIONS and show the MODEL and the COLOR using the combobox but disabled.. (like disabled='disabled' tag)....

 

Is that possible?

 

Thx!


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 17 July 2013 - 11:50 AM

There is a trick in this, never tried working on it directly but you surely can

/Here was the trick. Identify if the operation was Unknown / List then redirect it the users 
//profile update page
   $state_code = $crud->getState();
   if($state_code == 'edit') {
        $crud->change_field_type('field1', 'disabled');
   }

Technically this should work.


Charles A.

Charles A.
  • profile picture
  • Member

Posted 20 July 2013 - 19:44 PM

Hi Amit, thanks for your reply! But it doesnt  work at all... 

 

The field i'm trying to disable it's a combobox (retrieving the name from other table with a relation_n) 

 

So, when I apply your code, only shows an input box with the ID (not the name or description) and yes, disabled... 

 

Is there any way to show the text instead the ID ? Car_color.name (YELLOW) instead of Car_color.id (7) for ex ?

 

Thanks!!


davidoster

davidoster
  • profile picture
  • Member

Posted 20 July 2013 - 22:15 PM

I suggest you use the callback_field and you change from there whatever you need.

Or to be more precise callback_edit_field.


Charles A.

Charles A.
  • profile picture
  • Member

Posted 22 July 2013 - 03:21 AM

Thanks David! I've used callback_edit_field() as you suggested; and inside the callback function I used function from a model to retrieve the information from the database and replace the combobox with an input text (disabled).

 

Thanks!


yoandry

yoandry
  • profile picture
  • Member

Posted 26 January 2016 - 18:49 PM

$state_code = $crud->getState();
            if($state_code == 'edit') {
                $crud->field_type('field_x', 'readonly');
            }