Frage

I'm building a page that programmatically populates a form containing dojox.form.ValidationTextBox widgets based on data passed from a server. These widgets need to be validated before the form is submitted, but we currently don't have a way for the server to communicate the validation constraints.

Serializing the profile object used with dojox.validate.check seems like the best fit, but the structure is not completely serialization-friendly. The profile object passed to dojox.validation.check should have the following format:

 profile: {
      required: [fieldName1],
      constraints: {
           fieldName1: [[validationFunc1, constraintArg1, constraintArg2], [validationFunc2, constraintArg3, constraintArg4]]
           fieldName2: validationFunc3
      }
      .
      .
      .
 }

Since the profile object contains functions, we don't want to use it as-is. I was considering just serializing the name of the function to use in place of the function itself, but that would introduce some tight client-side coupling since there aren't supposed to be any global variable names with the dojo AMD loader.

Is there a more standard way of communicating (preferably with dojo) form validation constraints between a client and server?

War es hilfreich?

Lösung

The dojox.validate.check validation profile doesn't allow specifying custom a field's invalid messages. For example, say you use dojox.validate.isText as one validation function, providing constraints such as "maxlength" and "minlength" to it, you wouldn't get custom "invalid" messages that would display something like " cannot be more than characters long" if it was too long, or " must be longer than characters long" without a significant amount of code to manage that.

I would advise looking at other client side javascript validation frameworks, such as Regula or JQuery Validator and use a field constraints exchange format that would work better with one of those solutions.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top