1

I am developing custom shipping module for magento 2.2.

When you're filling out the Shipping Address form in Magento 2, periodically Magento will make an ajax request for the URL

http://magento.example.com/rest/default/V1/guest-carts/[hash]/estimate-shipping-methods

I changed postcode text field to autocomplete text field. Now when i type something in text field it make ajax request to above mention url. But after two or three character type, it shows auto suggest fields(which i added in autocomplte) and if I select one from that it doesn't generate any ajax call.

I added autocomplete code in my custom js as per below

setTimeout(function(){
        jQuery("input[name='postcode']").autoSuggest(data.items, 
        {
            selectedItemProp: "name", 
            searchObjProps: "name", 
            selectionLimit: 1, 
            minChars: 3,
            selectionAdded: function(elem)
            { 
                result = elem.text();
                getresultval(result);
            }
        }
        );
    }, 6000);

So, my problem is when I write on text box it works but when I select something from auto suggestion it doesn't work. That means issue is with binding event of postcode text field.

So how to resolve this?

  • Can you upload your code of autocomplete here ? – Emipro Technologies Pvt. Ltd. Apr 9 '18 at 9:17
  • @EmiproTechnologiesPvt.Ltd. I updated my question with code please check – Nirali Apr 9 '18 at 9:23
  • When you select from auto suggestion then ajax request should not be call & it's proper way. – Emipro Technologies Pvt. Ltd. Apr 9 '18 at 10:37
  • @EmiproTechnologiesPvt.Ltd. can you please explain why it's proper way? Because i need to implement this – Nirali Apr 9 '18 at 10:39

Your Answer

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

Browse other questions tagged or ask your own question.