Lock: Improve validator function in additionalSignUpFields (lock 10)

Created on 9 Jun 2016  路  3Comments  路  Source: auth0/lock

@gnandretta Currently there is no way to show an error text for invalid additional signup fields.

Perhaps the validator function can pass a callback function where if there's an error, the message can be passed through the first parameter like so:

var options = {
  additionalSignUpFields: [{
    name: "address",
    placeholder: "enter your address",
    validator: function(address, cb) {
      if (address.length > 10) cb();
      cb("Error: Address must be greater than 10 chars");
    }
  }]
}

Or maybe the validator can just be returned a string if there's an error:

var options = {
  additionalSignUpFields: [{
    name: "address",
    placeholder: "enter your address",
    validator: function(address) {
      if (address.length < 10) { return "Error: Address must be greater than 10 chars" }
    }
  }]
}

What do you think?

v10

Most helpful comment

@gnandretta
But it can use only pure functions, isn't it?
I mean what if I need to make a request to the server first and check whether the nickname is free?
Or any other asynchronous validation?

All 3 comments

This is included on 10.0.0-rc.2. Following your example, you'll use it like this:

validator: function(address) {
  return {
    valid: address.length > 10, // required
    hint: "Error: Address must be greater than 10 chars" // optional
}

@gnandretta
But it can use only pure functions, isn't it?
I mean what if I need to make a request to the server first and check whether the nickname is free?
Or any other asynchronous validation?

Version 10.11.0 still doesn't support callbacks for custom field validators. Is there a reason not to support this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cgcote picture cgcote  路  3Comments

ndelvalle picture ndelvalle  路  8Comments

mcrawshaw picture mcrawshaw  路  5Comments

sandrinodimattia picture sandrinodimattia  路  6Comments

dharness picture dharness  路  6Comments