⚠ 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

Disable or enable a dropdown list



Henri72
  • profile picture
  • Member

Posted 20 October 2012 - 13:13 PM

I wanted to create a disable / enable a dropdown list depending on whether a radio button is checked
Is there an easy way to do that ?

Henri72
  • profile picture
  • Member

Posted 26 October 2012 - 16:47 PM

Any idea ? :(

victor
  • profile picture
  • Member

Posted 27 October 2012 - 12:00 PM

HI,
Henri72 and welcome to the forum :).



//it's controller's code


$crud = new grocery_CRUD();
$crud->set_table('videos');
$crud->set_relation('videos_parent','videos_groups','title');


// field "check" is checkbox which will show/hide dropdown

$f=array('check','videos_parent','file_name','videos_title');

$crud->add_fields($f);
$crud->edit_fields($f);

$crud->callback_edit_field('check',array($this,'callback_check'));
$output = $crud->render();



the callback funciton returns a checkbox and javascript code

function callback_check()
{
return '

<script type="text/javascript">

$(document).ready(function(){

$("#ch").click(function(){
if ($("#ch").is(":checked")==false){
$("#videos_parent_field_box").hide(200);
}else{
$("#videos_parent_field_box").show("");
}
})
})
</script>
<input type="checkbox" name="ch" id="ch" />';
}

victor
  • profile picture
  • Member

Posted 27 October 2012 - 13:12 PM

This code show/hide a dropdown list, but you can change it as you like.

larasmith
  • profile picture
  • Member

Posted 14 August 2014 - 11:36 AM

Dear victor,

 

Thank you for this! It helped me a lot  :)

 

Other topic, can I create a dynamic $where condition for the set_relation_n_n? I needed my set_relation_n_n to be dependent on a drop down so I was thinking of a way to make my $where condition to be dynamic... Can u help me? I did my research but I still cannot get it right...

 

Thanks in advance!