Giter Site home page Giter Site logo

Comments (6)

DmitryEfimenko avatar DmitryEfimenko commented on July 16, 2024 1

I think preventing form submission on pressing Enter makes better UX, so I'd vote on adding this to the directive. It's not hard either. Just add this to the link function:

$element.on('keypress', function (e) {
    // prevent form submission on pressing Enter as there could be more inputs to fill out
    if (e.which == 13) {
        e.preventDefault();
    }
});

from ngautocomplete.

wpalahnuk avatar wpalahnuk commented on July 16, 2024

Would something like the top answer here work for you:

http://stackoverflow.com/questions/1563062/prevent-form-submission-with-enter-key

There isn't currently an option in the module to disable the enter key from bubbling, but it's something I can look into implementing.

from ngautocomplete.

iamerikjolson avatar iamerikjolson commented on July 16, 2024

Will,

Thanks for the quick response. That jQuery did the trick. I added the below code to my controller.

$("#Autocomplete").keypress(function(e) {
  if (e.which === 13) {
    return false;
  }
});

from ngautocomplete.

monkeymonk avatar monkeymonk commented on July 16, 2024

+1

If not, what's the point of the options watchEnter ??

from ngautocomplete.

joarhem avatar joarhem commented on July 16, 2024

The "watchEnter" Option from ngAutocomplete enables the option that the fraction you typed in is autocompleted with the first shown option in the dropdown list when pressing enter key.
Whether you enable watchEnter or not makes no difference for triggered form submission on enter.

The developer just targeted another use case with the watchEnter option i guess.

I lately had the same problem and did some research. I think, that Dmitry's solution is currently the best one. However, It still not feels very comfortable for me to change the directive...

I'd be happy to get informed, when there is a more clean, maybe a module-built-in function for this issue ;)

from ngautocomplete.

monkeymonk avatar monkeymonk commented on July 16, 2024

In my case I use this to prevent submit on hitting enter :

    // prevent form to be submitted on enter
    google.maps.event.addDomListener($element[0], 'keydown', function (e) {
        if (e.keyCode === 13) {
            e.preventDefault();
        }
    });

Hope this help someone! ;-)

from ngautocomplete.

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.