Code Monkey home page Code Monkey logo

Comments (6)

kraaden avatar kraaden commented on May 24, 2024 1

You should delay the $(input).blur() call with setTimeout in onSelect, otherwise it will immedeately update the input field.

JS BIN

from autocomplete.

kraaden avatar kraaden commented on May 24, 2024

@MROALI

Please check the following branch (last commit):
https://github.com/kraaden/autocomplete/tree/inputrestriction

Is this something you are looking for?

from autocomplete.

MROALI avatar MROALI commented on May 24, 2024

Thankyou i tested it but not working. I don't know what i did wrong.

I can no more select value from the list. It's always keeping the initial value loaded in the input.

When i put a breakpoint in the select function it works, otherwise not working. Do you have any idea ?

This is my code :
`autocomplete({
minLength: 1,
input: address,
debounceWaitMs:200,
preventSubmit: true,
inputRestriction : 2,
minLength: 5,
fetch: function(query, update) {
query = query.toLowerCase();
$.ajax({
url: urlAPI + query,
type: "get",
crossDomain: true,
dataType: 'json',
success: function(data) {
var processedData = _instance.getAddressFromJson(data);
update(processedData);
}
});

          },
          onSelect: function(item, input) {
        	  var addressValue = item.name;
              if(postCode.length) {
            	  postCode.val(item.postCode);
            	  postCode.blur();
              }
              
              if(city.length) {
            	  city.val(item.city);
            	  city.blur();
              }
              
              if(postCode.length == 0 && city.length == 0) {
            	  addressValue = item.label;
              }
              
              $(input).val(addressValue);
              $(input).blur();
          }
      });`

from autocomplete.

thomasphilibert avatar thomasphilibert commented on May 24, 2024

Nice and simple feature kraaden, thank you.

from autocomplete.

thomasphilibert avatar thomasphilibert commented on May 24, 2024

Hi Krraaden,

Your solution work fine but, if you type partialy and dont select any value of list, the input get previous value:

Enregistrement de l’écran 2020-03-13 à 00 54 26

Best,
Thomas

from autocomplete.

stale avatar stale commented on May 24, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from autocomplete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.