Intro
This plugins adds an autocomplete feature on a select element where a French postal address is demanded.
The suggestions are provided by AJAX from the governments official API.
Code example
<div class="form-with-address2autocomplete">
<div><label>Adresse</label></div>
<div>
<select class="address2autocomplete" name="address"></select>
</div>
<div class="decomposed-fields">
<p>You might want to hide these fields</p>
<div>
<label>Numéro, rue</label>
<input name="address" />
</div>
<div>
<label>Code postal</label>
<input name="zip" />
</div>
<div>
<label>Ville</label>
<input name="city" />
</div>
<div>
<label>Latitude</label>
<input name="latitude" />
</div>
<div>
<label>Longitude</label>
<input name="longitude" />
</div>
</div>
</div>
Notes
To activate the feature on a dynamically loaded element, call the initializing function once the element is added to the DOM
initAddressAutocomplete();
Parameters
The plugin takes the following parameters in an object format:
- {String} classForm Name of the wrapper form's class to initialize
- {String} classFormInited Class to be added once the form is initialized
- {String} classSelect The target select's class
- {String} placeholder The placeholder text for the select
- {Int} minimumInputLength The minimum number of characters to launch the autocompletion
Example:
initAddressAutocomplete({
classForm: 'my-custom-wrapper-class',
classFormInited: 'my-custom-inited-class',
classSelect: 'my-custom-target-class',
placeholder: 'My custom placeholder text',
minimumInputLength: 10,
});