Checking select2 value on page load

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
labib saleh
Posts: 23
Joined: 2014-12-29 21:46

Checking select2 value on page load

Post by labib saleh » 2017-04-07 20:50

I need to check if a certain select2 item is empty either when editing or adding a new record, and I'm using this code in tablename-dv.js file:

Code: Select all

$j(function(){
	var itemid = $j('#Sel2').val();
	if(itemid == '{empty_value}'){
		//do something
	}
)
But for some reason it doesn't work! Do I need to use different line other than ('{empty_value}') to check if it's empty?

Thanks,
Labib

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

Re: Checking select2 value on page load

Post by labib saleh » 2017-04-07 21:10

[Update]
¯¯¯¯¯¯¯
I used (itemid != '{empty_value}') and my condition got applied, indicating that select2 is considered to have a value or something (although it's set to none!), is there a different way to verify other than '{empty_value}'?
___________________
I'm using appgini 5.51
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

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

Re: Checking select2 value on page load

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

[Update2]
¯¯¯¯¯¯¯¯¯
I wasn't able to figure out the thing about using '{empty_value}' for this issue, but found a different way to check if select2 item doesn't have a selected value, and thought of sharing it just incase someone else needed that. I used the following code and it did the job:

Code: Select all

$j(function(){
	var itemdata = $j('#Sel2-container').select2('data');
	if(itemdata == null){
		//do something
	}
)

Post Reply