The API has a call named RNVP which allows to test the completeness of the entered fields and to return an error code or suggestions of correction if necessary. This call also allows to extract the components of an address.
Check
To check an address, the call to the plugin must first be stored in a variable to be able to call the "check(callback)" method which will launch the check.
var options = {
server : 'classes/dqe.php',
country : '#id_country',
zip : '#id_zip',
city : '#id_city',
street : '#id_street',
compl : '#id_compl'
};
window.dqeObject = $('#id_form').dqe(options);
$('#btn_check_form').click(function() {
window.dqeObject.check('callback_func');
});
For the call to the "check" method, it is necessary to provide the name of the function that will be called at the end of the form check. This function will allow you to display an error message, highlight invalid fields or use the suggested corrections.
"Data" contains the different parts of the analyzed address as well as the following keys:
- label ;
- error ;
- corrections ;
- ilot ;
- status_iris_ilot ;
- normalized (normalized extracted parts of the entered address) ;
- known_numbers (if the number is missing in the entered address: list of available numbers for this street).
It is also possible to control a form that does not include the DQE auto-completion. To do so, you just have to provide a second parameter "address" which will contain all the fields to be controlled:
options = {
server : 'my_server_path',
country : '#id_country'
};
dqe = $('#id_form').dqe(options);
function rnvp() {
var address = {
compl : $('#id_compl').val(),
street : $('#id_street').val(),
zip : $('#id_zip').val(),
city : $('#id_city').val(),
country: $('#id_country').val()
};
dqe.check('callback_check', address);
}
Extraction of the different parts of the entered address
To extract the different parts of an address, the call to the plugin must first be stored in a variable in order to be able to call the "parse(callback, address)" method which will launch the analysis of the address passed in parameter.
The result passed back to the callback function contains all the keys related to a form control (see part 4.C Form control).