The Value of --None-- in onChange Client Script

yundlu316
Kilo Guru

Hi Everyone, I'm trying to write a simple onChange client script that clears values based on an answer:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue==='') {
		return;
	}

	if(g_form.getValue('relation_to_employee').indexOf("child") == -1) {
		g_form.clearValue('x_dnf_gw_found_type_of_child');
		g_form.clearValue('x_dnf_gw_found_dependent');
	} 
}

So if Relation to Employee does not equal "child" then I want to clear the values for Type of Child and Dependent fields.  This works fine, but the Relation to Employee drop down has "-- None --'" and for some reason, this doesn't work.  I've tried changing my if statement to the following but it still doesn't work:

if(g_form.getValue('relation_to_employee', '!=','child') || g_form.getValue('relation_to_employee','')){

Any suggestions on how to fix this?  Thanks!

 

1 ACCEPTED SOLUTION

Jace Benson
Mega Sage

The option of "--None--" has a value of "".  If you change your script to this it should work;

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading) {
		return;
	}

	if(g_form.getValue('relation_to_employee').indexOf("child") == -1) {
		g_form.clearValue('x_dnf_gw_found_type_of_child');
		g_form.clearValue('x_dnf_gw_found_dependent');
	} 
}

View solution in original post

5 REPLIES 5

Jace Benson
Mega Sage

The option of "--None--" has a value of "".  If you change your script to this it should work;

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading) {
		return;
	}

	if(g_form.getValue('relation_to_employee').indexOf("child") == -1) {
		g_form.clearValue('x_dnf_gw_found_type_of_child');
		g_form.clearValue('x_dnf_gw_found_dependent');
	} 
}

Thanks!!

Hi, I have a similar issue. 

I have a client script which populates the subcategory based on category chosen. Category is actually dependent on another field called support area. when we have a category which only has one subcategory, the client script will automatically populates the subcategory. Once it's populated, not able to clear it which runs on the change of Support area field. 

find_real_file.png

 

I'd suggest opening a new post on this different issue.  I don't have a fast/quick answer. Sorry.