getting all validation control funcs


Badge +4

Lets say I want to make style for nintex error validation - by putting it below the control.

I have a code doing it (It's free, just take it happy.png :

function validateRequiredField(fieldClientId, errorMsg) { var NWF$this = NWF$('#' + fieldClientId); var NWF$errorEl = NWF$this.parent().siblings('.nf-validator-error').first().length ? NWF$this.parent().siblings('.nf-validator-error').first() : NWF$this.parent().parent().siblings('.nf-validator-error').first(); if (NWF$this.val()) { NWF$errorEl.text('').hide(); return true; } else { NWF$errorEl.text(errorMsg).show(); return false; } }

JUST ADD SOME CSS)

Anyway, I want to get all the control's specific validation and put it into array. How can I get it?


3 replies

Userlevel 5
Badge +14

At which point do you want to get them? 

During validation? 

All of the Validation Spans can be found in the Page_Validators global variable, and on each one of those <span> elements is a property called "controltovalidate". 

If you have the prop id of the control element that you'd like to find all of the validators for, you can use something like:

var someControlID = "blahblahblah";
var defaultControlValidators = [];
var customControlValidators = [];

Page_Validators.filter(function (element) {
  return (element.controltovalidate === someControlID);
}).forEach(function (element) {
  /* If the Validator has a ruleId property assigned to it
    we know that it's a customControlValidator and can push it into
    our array (as a jQuery Object). */

  if (element.ruleId) {
    customControlValidators.push(NWF$(element));
  } else {
    /* if it doesn't have a ruleId property, then we know that it's an
      inherent (aka: default) validator and can be pushed into our
      defaultControlValidators array as a jQuery Object. */

    defaultControlValidators.push(NWF$(element));
  }
});

It honestly all depends on when you'd like to capture this information... but that should get you (or this conversation) started. 

Badge +4

I want to capture it on page loading. I want to capture the funcs of all of the controls in current form

Userlevel 5
Badge +14

well then yeah. You can use the above method to go through each of your controls and then through all of the ID's of that control, and grab all of the Page_Validators that are associated to that ID. 

However, by doing it this way you're going to have a bad time when you start getting into Repeating Sections (you'll need to push all of the new Validators into your object with each Row Add and Remove them with each Row Delete), and while Controls like Single Line Text have a straight forward way of getting their ID, there are many controls, such as lookup and choice, that have multiple IDs associated to one Control. 

If you're just trying to style the form anew based on the validation state, I would recommend at my blog about the Rule System over here: Breaking The Rules: A Dive Into The Nintex Forms Rule System, and a follow up post by a fellow community member who put together a real-time validation styling system here:   


Reply