Not applicable

form validation based on decision variable

The Nintex form has 3 buttons- Save, Submit and Cancel. As the name suggests SAVE - saves the data on the form; SUBMIT- (save & submit) moves on to the next stage; but CANCEL- is also used as a "save & submit" button since the workflow is supposed to update a few fields and then cancel the running workflow.

There are some Javascript validation on the Nintex form and I would not want the validations to be checked when I select "CANCEL". I tried to get the decision variable and included it in the javascript condition . but this didn't serve my purpose.

Can anybody help me with this?

0 Kudos
Reply
1 Reply
andrewg
Automation Master
Automation Master

Re: form validation based on decision variable

Let me ramble a couple of thoughts, but hopefully it will help in some way.

You could have a custom function called on the button click that sets a variable that a validation function can check and skip if this variable is set.

If you are using javascript validations like below, they could be over written

SPClientForms.ClientValidation.RequiredValidator = function() {

};

SPClientForms.ClientValidation.RequiredValidator.prototype.Validate = function(value) {

  value = SPClientTemplates.Utility.Trim(value);

  var hasError = value === '';

  var errorMsg = hasError ? Strings.STS.L_SPClientRequiredValidatorError : '';

  return new SPClientForms.ClientValidation.ValidationResult(hasError, errorMsg);

};

But the one I use the most is override the PreSaveAction function. All list item saves call the client side function PreSaveItem of

function PreSaveItem()

{  

   if ("function"==typeof(PreSaveAction))

   {

      return PreSaveAction();

   }

   return true;

}

So if you implement PreSaveAction() with the following you are now checking for Email input validity.

function validateEmail(email) {

    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

    return re.test(email);

}

function PreSaveAction(){

    var emailBox = getFieldControl('Email','Text');

    if (!validateEmail(emailBox.val())) {

        var errorHtml = '<span class="ms-formvalidation"><span role="alert">Invalid email address<br></span></span>';

        emailBox.after(errorHtml);

        return false;

    }

    return true;

}

function getFieldControl(fieldName,fieldType)

{

    var control = $('[id^=' + fieldName + '_][id$=' + fieldType + 'Field]');

    return control;

}

So possibly, you could have a function called on the Cancel button to set a flag, then run the PreSaveItem. But in your PreSaveAction custom function on the form, it can check the flag if it is set.

I'm sorry I do not have an example of my own code, but these are some recollections of actions I have performed in the past. Also, I copied this code from the following blog Introduction to Client Forms Validation in SharePoint 2013 | YASP Blog it may explain it further for more help.

0 Kudos
Reply