Git Product home page Git Product logo

Comments (6)

dyve avatar dyve commented on July 29, 2024

Please copy/paste the fix for the second issue.

preventDefaultReturn means that the default behavior of return is
suppressed when the autocompleter is active. The autocompleter is
active when you are typing in the field. So as far as I can tell, the
behavior you are describing is correct.

On Sat, Mar 24, 2012 at 01:39, webtweakers
[email protected]
wrote:

It may be a silly question, but I was wondering if the current behavior of the return key is a bug? I mean, I noticed that if you start typing a name that appears in the autocomplete list (which beautifully appears, mind you!) and don't select the item, but just press the return key - nothing happens. What I would expect is the form to be submitted with the input of the form field(s)!

This is the case with the preventDefaultReturn option set to true, and I'm explicitly NOT selecting an item from the autocomplete list.

Also, I'm using the autocomplete on an input field with css rule position:fixed. When the page is scrolled down a little, and one starts typing, the autocomplete div appears a distance below the input box, similar to the distance scrolled. I fixed this bug, but I'm new to github, so I'll read the tour before I screw something up. :) I can copy/paste the fix here, if requested.

Cheers and thanks for the great work!


Reply to this email directly or view it on GitHub:
#35

from jquery-autocomplete.

webtweakers avatar webtweakers commented on July 29, 2024

Hm, maybe I didn't explain myself right. :)

I understand that the preventDefaultReturn option exist to make the return key submit the form with the CHOSEN item from the autocomplete list, whereas by default this would submit the form with the input field.

However, there doesn't seem to be a way to let the form submit on return key with the value form the input field, if no item is chosen.

Setting preventDefaultReturn to false, will submit the form with the input field, regardless of a choice - which is of course not what one wants...

So let me turn this into a question then: how do i let a user submit the form, while pressing the return key, when he/she did not choose an item from the autocomplete list?

The fix for the fixed-positioned input, I have implemented like this:

  1. add a default option to the end of the list (approx. line 84):

    positioning: 'absolute' // either 'absolute' or 'fixed'
  2. add/change code around line 315 (set position according to option and precalc pos of autocomplete div):

    // Create DOM element to hold results, and force absolute position
    this.dom.$results = $('<div></div>').hide().addClass(this.options.resultsClass).css({
        position: this.options.positioning
    });
    $('body').append(this.dom.$results);
    
    // @property {number} Top of the result div
    // @private
    this.elmTop_ = this.options.positioning == 'fixed' ? this.dom.$elem.offset().top + this.dom.$elem.outerHeight() : 0;
  3. finally update the position method to make use of the above:

    $.Autocompleter.prototype.position = function() {
        var offset = this.dom.$elem.offset();
        this.dom.$results.css({
            top: this.options.positioning == 'absolute' ?
                offset.top + this.dom.$elem.outerHeight() : this.elmTop_,
            left: offset.left
        });
    };

I imagine it can be done easier, by detecting the position of the input box and to make sure the position method is called at the right time, or something along those lines...

from jquery-autocomplete.

webtweakers avatar webtweakers commented on July 29, 2024

So, for clarity, steps to reproduce: start typing something that should spawn the autocomplete list. Ignore the contents, do not select anything and just press return. The autocomplete box will disappear and nothing else will happen.

The selectFirst option is false and the preventDefaultReturn option is true.

I want the form to be submitted with the contents of the input box, when no item from the autocomplete list is selected.

Note: if you type something that does not spawn the autocomplete box, then everything will work fine and enter will submit the form the usual way. This functionality is blocked when the autocomplete appears.

from jquery-autocomplete.

dyve avatar dyve commented on July 29, 2024

This is intended behavior. The autocompleter is active when spawned, regardless of an active selection. However, I can understand that this is confusing, I have to think about whether or not to adjust behavior.

from jquery-autocomplete.

webtweakers avatar webtweakers commented on July 29, 2024

I see. Well, the preventDefaultReturn option is meant for when an item in the autocomplete list is selected, and what to do when the return key is pressed. There is no option for the case where NO item in the list is selected, as far as I know. Maybe an option like submitWithoutSelection, or something similar, would make sense...? But maybe that confuses even more.

Pressing escape, to close the autocomplete, and then return works fine. But it's not how I want this to work...

from jquery-autocomplete.

webtweakers avatar webtweakers commented on July 29, 2024

I noticed rizzoma fixed this issue, shortly after I started this topic. :) thanks!

from jquery-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.