Page 1 of 1

How to apply jQuery in select2?

Posted: 2017-01-16 08:07
by hbcornea
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.

Re: How to apply jQuery in select2?

Posted: 2017-04-18 23:40
by labib saleh
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:

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);
		}
	});
})