Question

How can I get parsley to include more fields in its AJAX-Calls, so that I can test dependencies between these fields?

Example:

<form method="post" action="/myscript.php" data-parsley-validate>
   <input type="text" name="i1" 
          data-parsley-group="g1" 
          data-parsley-remote="/myvalidator.php"
   />
   <input type="text" name="i2" 
          data-parsley-group="g1" 
          data-parsley-remote="/myvalidator.php"
   />

   <button type="submit">Send</button>
</form>

Currently the $_POST-data only contains the field being validated, but I'd need to know the input of other fields in the same group. BTW, this setup triggers other questions, like the sequence of validation (i1 cannot be evaluated before i2 is filled, too - but I'd be happy to only validate i2 and pass the value of i1 in that call).

Était-ce utile?

La solution

I have managed to send additional parameters by setting them as the default for jQuery ajax. For example, at the bottom of the page where my validator is used:

<script type="text/javascript">
    $.ajaxSetup({
            beforeSend: function(xhr, settings) {
                settings.url += "&id=" + $('#host').val();
            }}
    );
</script>

The jQuery documentation strongly advises against using the setup method in this manner, since it will affect any other ajax requests on the page. If your page is not too busy though, it may be a reasonable work around until something better becomes available in the Parsley library. Read more about it here, http://api.jquery.com/jQuery.ajaxSetup/

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top