0

I use Mesosphere and I want to make a custom rule to validate equalsField:

Mesosphere.registerRule("equalsField", function(fieldValue, ruleValue){
  //var ruleValue = $('#'+ruleValue).val();
  //var ruleValue = document.getElementById(ruleValue).value;
  return fieldValue === ruleValue;
});

But I can't use jquery $ or document because is not accesible on the server side (these works only on the client side)

ciocan
  • 47
  • 4

1 Answers1

0

So it looks like what you want to to is check that one field is equal to another field.

In actuality when a rule is validated in Mesosphere, the rule is passed 5 parameters: fieldValue, ruleValue, fieldName, formFieldsObject, and fields. Since formFieldsObject is an object containing the raw unvalidated data from the form, with the name of each input as the key and the current value as the key value, This means that you can create your new rule as follows..

Mesosphere.registerRule("equalsField", function(fieldValue, ruleValue, fieldName, formFieldsObject, fields){
  return fieldValue === formFieldsObject[ruleValue];
});

Then when you set up your rules, pass the name of the field that the current field should be equal to and you should be good to go.

Kelly Copley
  • 2,990
  • 19
  • 25