2

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).

MBaas
  • 7,248
  • 6
  • 44
  • 61
  • 1
    MBass, I have a similar question, http://stackoverflow.com/questions/23690448/parsley-remote-and-additional-parameters – DatsunBing May 15 '14 at 23:40
  • 1
    Thanks Kim - funny coincidence that we came up with that issue on the same day. Hope we'll get a solution, too ;) – MBaas May 16 '14 at 04:41
  • 1
    Hey MBass, even more coincidentally, seems that a solution was posted here about 20 hours ago!, https://github.com/guillaumepotier/Parsley.js/pull/645 – DatsunBing May 16 '14 at 06:29
  • 1
    Wow, what a nice coincidence - that should help to fix the problem. Can you pls. post this as answer, then I can close the issue and you get the points ;-) – MBaas May 16 '14 at 06:31
  • 1
    Hi MBaas, not sure that the existing github issue will resolve our problem, so I have opened another, https://github.com/guillaumepotier/Parsley.js/issues/648. It would be good if you could add a comment to it, so the developer knows there is a demand for it... – DatsunBing May 22 '14 at 05:31
  • 1
    Thanks! Been there, done that ;-) – MBaas May 22 '14 at 19:56

1 Answers1

2

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/

DatsunBing
  • 8,684
  • 17
  • 87
  • 172