Hi @Anonymous,
This is a different validator - basically this validator is the same as a range validator (number must be between 0 and 100) or a required field validator, which the page will automatically search for on submit.
Either process would work. The original text block is probably the simplest, as all you have to do is replace the "return true;" with your comparison logic and a resulting true false - e.g.
return fieldToken === token;
However, the CRM Hub link will build a validator that has an error message and a link to the field that is wrong. If this is the desired behavior, see comments added to the original code here:
// Apply Client Side Validation on FieldName
if (window.jQuery) {
(function ($) {
$(document).ready(function () {
if (typeof (Page_Validators) == 'undefined') return;
// Create new validator
var newValidator = document.createElement('span');
newValidator.style.display = "none";
// JB: Replace the string "FieldNameValidator" with anything you want to be the validator key - is not shown to the user.
newValidator.id = "FieldNameValidator";
// JB: Replace "FieldName" with the schema/control ID of either your field token or token in the next few lines except the anchor text - e.g. "FieldName" -> "new_fieldtoken", "#FieldName_label" -> "#new_fieldtoken_label", "FieldName is required field." -> "Field Token does not match Token."
newValidator.controltovalidate = "FieldName";
// JB: Replace
newValidator.errormessage = "<a href='#FieldName_label'>FieldName is required field.</a>";
// JB: You can ignore this - this is only used if you want to validate groups of fields together without a submit.
newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
newValidator.initialvalue = "";
// JB: here is your function.
newValidator.evaluationfunction = function () {
var FieldToken = $("#new_fieldtoken").val(); // replace with actual
var Token = $("#new_token").val(); // replace with actual
if (FieldToken !== Token)
return false; // return false means SHOW ERROR MESSAGE
else
return true; // return true mean successful
};
// Add the new validator to the page validators array:
Page_Validators.push(newValidator);
// Wire-up the click event handler of the validation summary link
// JB: Replace 'FieldName' with same field as before (e.g. new_fieldtoken)
$("a[href='#FieldName_label']").on("click", function () { scrollToAndFocus('FieldName_label','FieldName'); });
});
}(window.jQuery));
}