I am trying to use the remote validator with Parsley and I can't seem to send additional data with the request. The field in question is an email field, and I want to send it to the server to see if the email address is 'available'. In addition, I need to send an id parameter which the server requires. The id parameter is embedded in my form in the 'host' field.
So, I have tried using the Parsley DOM API as follows:
<input type="text" class="form-control" tabindex="15" id="email" name='email'
data-parsley-type="email" data-parsley-type-message="Must be a valid email format"
data-parsley-required="true" data-parsley-required-message="Email is required"
data-parsley-remote="/invitation/allowed"
data-parsley-remote-options='{ "type": "get", "data" : { "id": function() {return $("#host").val(); } }}'>
In the final line of the API config I have tried various combinations to get the value of the host field into my URL. These include escaping the quotes in the function; and proving 'host' (or '#host') as the value of the id property. In each case I can get only my email address passed in the URL.
Note that I can pass a literal no problems (for example { "id": "TestTest" }
).
I have also tried using javascript as follows:
<script type="text/javascript" src="/js/parsley.remote.js"></script>
<script type="text/javascript">$('#employee-form').parsley({})</script>
<script type="text/javascript">
$('#email').parsley().addConstraint('remote',
{
url: '/invitation/allowed',
type: 'GET',
data: {
id: function () { return $('#host').val() }
}
})
</script>
When I do this I have two problems: the id is not set in the URL, and also the base url is incorrect - it calls the address of the current page (not /invitation/allowed).
This question, which was asked a few hours ago, is similar: Remote validation for a field which depends on others