Choice field is disappears after saving form

Jerry33
Tera Contributor

Hi,

I have a choice field that is hidden with one UI Policy.  I need that field to show up when a date field is updated.  I was able to have the choice field display with a second UI policy but it disappears after saving the form.  The order between the ui policies are different.  Is there a way to do a client script to hide the field and show when date field is updated?

Thanks

1 ACCEPTED SOLUTION

-O-
Kilo Patron
Kilo Patron

One could move all mandatory and visibility controls for the Choice field into a Client Script (as UI Policies are executed after Client Script and would overwrite whatever the Client Script instructs). One could write an onChange Client Script for the Date field, something like:

function onChange (control, oldValue, newValue, isLoading, isTemplate) {
	if (has_date_field_been_modified(oldValue, newValue))
		show_choice_filed('<choice field name>');
	else
		hide_choice_filed('<choice field name>');

	function has_date_field_been_modified (oldValue, newValue) {
		return oldValue != newValue;
	}

	function hide_choice_filed (fieldName) {
		g_form.setMandatory(fieldName, false);
		g_form.setVisible(fieldName, false)
	}

	function show_choice_filed (fieldName) {
		g_form.setVisible(fieldName, true)
		g_form.setMandatory(fieldName, true);
	}
}

 

View solution in original post

2 REPLIES 2

Aoife
Tera Guru

Add a condition on your first one to show not only when the date field is updated but also when the choice field has a value selected.  Then you do not need the second one.

Aoife

-O-
Kilo Patron
Kilo Patron

One could move all mandatory and visibility controls for the Choice field into a Client Script (as UI Policies are executed after Client Script and would overwrite whatever the Client Script instructs). One could write an onChange Client Script for the Date field, something like:

function onChange (control, oldValue, newValue, isLoading, isTemplate) {
	if (has_date_field_been_modified(oldValue, newValue))
		show_choice_filed('<choice field name>');
	else
		hide_choice_filed('<choice field name>');

	function has_date_field_been_modified (oldValue, newValue) {
		return oldValue != newValue;
	}

	function hide_choice_filed (fieldName) {
		g_form.setMandatory(fieldName, false);
		g_form.setVisible(fieldName, false)
	}

	function show_choice_filed (fieldName) {
		g_form.setVisible(fieldName, true)
		g_form.setMandatory(fieldName, true);
	}
}