Hi,
I am looking for a guidance on customizing select2. I wanted to disable the input text when I select on select2. Eg., If I select "no", there will be disabled text input. If "yes", its enabled.
Please help. Thank you.
How to apply jQuery in select2?
-
- Posts: 23
- Joined: 2014-12-29 21:46
Re: How to apply jQuery in select2?
Hello hbcornea,
I was searching for something else and stop by your question, I know it's too late but thought of sharing the solution incase you or someone else is still looking for it
Assume your table is called 'orders', your select2 item is called 'seldecide' and your textbox is called 'txtfill'.
You'll need to create a file called 'orders-dv.js' inside your hooks folder and use the following code there:
I was searching for something else and stop by your question, I know it's too late but thought of sharing the solution incase you or someone else is still looking for it
Assume your table is called 'orders', your select2 item is called 'seldecide' and your textbox is called 'txtfill'.
You'll need to create a file called 'orders-dv.js' inside your hooks folder and use the following code there:
Code: Select all
$j(function(){
$j('#seldecide-container').on('change', function(){
var data = $j('#seldecide-container').select2('data');
if(data.text == 'No'){
$j('#txtfill').prop('readonly', true);
}else if(data.text == 'Yes'){
$j('#txtfill').prop('readonly', false);
}
});
})