Options
* — Required option
Option | HTML attribute | Type | Description |
---|---|---|---|
crossDomain |
data-fv-remote-crossdomain |
Boolean | It's same as the crossDomain option of jQuery's ajax. |
data |
data-fv-remote-data |
Object|Function |
The data sent to remote URL. You don't need to use this option if there is only field, defined as field name, sent to the remote URL. If you want to use dynamic data, then use a callback as following: When using |
dataType |
data-fv-remote-datatype |
String |
The type of data which is returned by remote server. It's same as the
The available values are |
delay |
data-fv-remote-delay |
Number | The Ajax request created by the remote validator is only fired once in the delay duration time. |
message |
data-fv-remote-message |
String | The error message. The dynamic message is supported |
name |
data-fv-remote-name |
String | The name of field which need to validate |
type |
data-fv-remote-type |
String |
The method used to send data to back-end. It can be From v0.5.2, the type option is
GET, by default.
|
url * |
data-fv-remote-url |
String|Function | The remote URL. If you want to use a dynamic URL, then use a callback as following: |
validKey |
data-fv-remote-validkey |
String |
The valid key. It's This option is useful when connecting to external remote server or APIs provided by 3rd parties. |
The crossDomain
, dataType
, validKey
options are
mostly used when you need to connect to external API endpoint. This example shows how to
connect and use the Mailgun API to validate an
email address.
The remote URL has to return an encoded JSON of array containing the valid
key (the key name can be changed by the validKey
option):
or
Improving the performance
By default, the plugin will send an Ajax request to your back-end whenever you enter a character in field. If the back-end takes time to process the request, it might slow down the website. In order to improve the performance, you can use following tips:
Using delay option
By setting the delay
option, the Ajax request is only fired once in the
specific duration time.
Using threshold option
The threshold option indicates value that asks validators not to perform validations unless the length of field value is greater than this number.
In the snippet code below, the remote validator will not send Ajax request until the username field has at least 5 characters:
Using verbose option
Client first, server last. If the field uses multiple validators, the validators processed in the client should be done first. The remote validator is only processed once the field passes all other validators.
Using the verbose option is solution for this
approach. Setting verbose: false
will stop validations when there is one
failure validator.
In the following code, the remote validator is only processed if the field satisfies all notEmpty, stringLength, regexp validators.
ejemplos
Basic example
The following example shows how to use a remote back-end to check if a given username is already taken or not.
Sending static data example
For example, there is same back-end for validating both username and email address. The
back-end uses additional parameter named type
to determine which field is
going to be validated.
Sending dynamic data example
For instance, the registration form need to validate both the username and emails.
Overriding name example
By default, it will be set as the name of field. You can override the name option by
using the data-fv-remote-name
attribute.Here are two cases which you might
need to use this attribute.
Using different names for same field
For example, the Sign up and Profile forms use the same back-end URL to validate the email address which is declared with different name.
In this case, use the same data-fv-remote-name
attribute and the back-end
will get the same data key.
Using same backend for different fields
Assume that the profile form asks you to update multiple email address (primary, secondary, for example). These emails will be validated by the same backend.
In this case, just use the same data-fv-remote-name
attribute for these
email address fields.
More ejemplos
Related validators
The following validators might be useful to you: