How to apply jQuery in select2?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
hbcornea
Posts: 3
Joined: 2017-01-12 07:54

How to apply jQuery in select2?

Post by hbcornea » 2017-01-16 08:07

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.

labib saleh
Posts: 23
Joined: 2014-12-29 21:46

Re: How to apply jQuery in select2?

Post by labib saleh » 2017-04-18 23:40

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

Post Reply