0

I have an exposed views form, am geolocating in javascript and setting the co-ordinates in the exposed form.

This form submits properly when I click on the 'apply' button but does not when I use javascript to submit the form. The page refreshes, but the values have not been changed.

The form is standard FAPI. It is not a views-ajax form although I would like to move to ajax at some point in the future when I sort out the problems with gmaps + ajax.

Both of the following fail.

jQuery('#edit-submit-studio-locations').click();
jQuery('#views-exposed-form-studio-locations-page').submit();

The full code is in github.

1

Add this code inside Drupal.behaviors.

$('.views-exposed-form APPLY_BUTTON ID/class').click(function() {
  // Submit the form
  (this).parents('form').submit();
});

Hope it works.

0

You can submit form using jquery or add some trigger action

here is example code :

Drupal.behaviors.form_submit_processor = {
  attach: function (context, settings) {
    $("form#your-form").submit(function(e) {
     // some code here
    });
  }
}
  • Is there a way I can get this to fire when only a certain form is submitting. As this js runs for all form submissions true? – albo Feb 26 '17 at 11:54
0

Apologies, the problem was that the geocoding was being done asynchronously. Both of these submission methods work.

The solution is to trigger an event in the geocoding closure and react to this event.

I thought FAPI was somehow validating my submission.

geocoder.geocode({'address': address_string}, function (results, status) {
  $(window).trigger('yhive_geocoded');
});

$(window).on('yhive_geocoded', function() {
      $('#views-exposed-form-studio-locations-page').submit();
});
0

The following would do the job:

jQuery('#edit-submit-studio-locations').mousedown();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.