Custom validation for Nintex form controls using JavaScript validators:
Sometimes Nintex forms controls require some special validation to be enforced which cannot be met
by default Nintex forms validation rules. In such situations, custom validation using JavaScript validators
can be used. For e.g. in the Nintex people picker, the requirement was to show a custom validation error
message when the user entered in the people picker could not be resolved.
In order to implement this, a client id was assigned to the Nintex people picker control. Also, in the
‘Validation’ section of the control settings, ’Use Custom Validation’ property was set to yes and the
name of the JavaScript validation function and the custom validation error message was specified.
After this, the code for this validator function was added in the custom JavaScript section of the form.
Whenever this function returned a false, the custom validation error message specified was displayed.
function ValidateOnboardingContactPersonField(obj,args)
{
var peopleControl = NWF$('#' + varOnboardingContactField);
var people = peopleControl.val();
var peopleText=NWF$.trim(peopleControl.parent().find('textarea').val());
if (people == '' && peopleText == '')
{
args.IsValid = true;
}
else if (people == '' && peopleText != '')
{
args.IsValid = false;
}
else
{
var arr_people = people.split(';').filter(function(n){ return n.length != 0 });
args.IsValid = (arr_people.length === 1);
}
}
by default Nintex forms validation rules. In such situations, custom validation using JavaScript validators
can be used. For e.g. in the Nintex people picker, the requirement was to show a custom validation error
message when the user entered in the people picker could not be resolved.
In order to implement this, a client id was assigned to the Nintex people picker control. Also, in the
‘Validation’ section of the control settings, ’Use Custom Validation’ property was set to yes and the
name of the JavaScript validation function and the custom validation error message was specified.
After this, the code for this validator function was added in the custom JavaScript section of the form.
Whenever this function returned a false, the custom validation error message specified was displayed.
function ValidateOnboardingContactPersonField(obj,args)
{
var peopleControl = NWF$('#' + varOnboardingContactField);
var people = peopleControl.val();
var peopleText=NWF$.trim(peopleControl.parent().find('textarea').val());
if (people == '' && peopleText == '')
{
args.IsValid = true;
}
else if (people == '' && peopleText != '')
{
args.IsValid = false;
}
else
{
var arr_people = people.split(';').filter(function(n){ return n.length != 0 });
args.IsValid = (arr_people.length === 1);
}
}
Comments
Post a Comment