⚠ 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 hide fields in ADD & EDIT when specific choice is made into another field ?



lcoulon
  • profile picture
  • Member

Posted 21 January 2019 - 14:53 PM

Hello,

 

I have a dropdown list with choices 'choices' , how could i show another field that is a textbox named 'textbox' when user selects 'C' choice in ADD and EDIT forms ?

$crud->field_type('choices','dropdown', array(
'A' => 'A',
'B' => 'B',
'C' => 'C',
'D' => 'D'
));

My approach is trying to hide the field 'textbox' when 'choice' is NOT 'C'

I tried the following in Main.php, but it does not work.

if ($crud->getState() == 'edit') && ($crud->getState() == 'add')
{
    $field_value = $crud->get_edit_field_value('choices');
    
    if ($field_value != 'C'){
        
    $crud->field_type('textbox', 'hidden');
    }
};   

Your help will be much appreciated.

Thank you,


mdqseba
  • profile picture
  • Member

Posted 06 February 2019 - 17:34 PM

hello, check the "if" sentence.....


if ($crud->getState() == 'edit') && ($crud->getState() == 'add')

{.......

 

 

is correct?