Hello,

I'm using addressfield to store address information for my user profiles. Running some tests i was scared having some users with 0 as country, even though i was sure i selected a real country from the dropdown...

In the end, i think i found out that it happened because i submitted the form too fast so the ajax called after the country is selected was not completed yet.

So on one of my modules i added a JS aiming to disable the form submit button during the ajax call and here it is:

(function ($) {
  Drupal.behaviors.stopFormWithNoCountry = {
    attach: function (context, settings) {
      $("body", context).once("stopFormWithNoCountry", function(){
        $("body").delegate("form.user-info-from-cookie select.country.form-select","focus",function(){
          $("form.user-info-from-cookie :submit").attr("disabled", "disabled");
          $(document).ajaxStop(function () {
            $("form.user-info-from-cookie :submit").removeAttr("disabled");
          });
        });
      });      
    }
  };
})(jQuery);

it kind of works, but still it is an ugly workaround and it would be way better to take care of this in the addressfield code, right?

Comments

joey-santiago’s picture

I would have liked better to trigger that function on the "change" event, but had no luck: it's not triggered. Why?

bojanz’s picture

Status: Active » Closed (duplicate)

The patch in #968112: Allow addressfield to be optional will make sure that nothing is saved to the database if the country is not selected.