Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-37204

AutoComplete does not trigger onChange when using enter to complete

      When using auto-completion on a textbox, and using the enter key instead of clicking the value to select a value in the drop-drown list, the onChange event is not triggered. That could make sense if it was when leaving the field, but it's not as well, I guess the browser thinks the value haven't changed since it is set via setting the value attribute directly on the input field, here is where it's happening:

      YAHOO.widget.AutoComplete._updateValue (autocomplete-mi…:formatted:995)
      YAHOO.widget.AutoComplete._selectItem (autocomplete-mi…formatted:1007)
      YAHOO.widget.AutoComplete._onTextboxKeyDown (autocomplete-mi…formatted:1204)
      n (event-min.js:7)
      

      Setting @value doesn't trigger a change event, and leaving the field either.

      This is a problem if we have validation as well using checkUrl or doCheck method, because the we can choose a value using enter, leave the field and the value will never be validated.

          [JENKINS-37204] AutoComplete does not trigger onChange when using enter to complete

          Guillaume DELORY added a comment - - edited

          I was investigating a bit more this issue, and what do you think about adding this at the auto-complete behavior:

          ac.itemSelectEvent.subscribe(function () {
            e.onchange();
          });
          

          in hudson-behavior.js#INPUT.auto-complete:688

          IMHO, it makes sense to trigger the change event when an element is selected in the auto-complete list, since looking at the code of the yahoo auto-complete library:

          YAHOO.widget.AutoComplete.prototype._selectItem = function(a) {
              this._bItemSelected = true;
              this._updateValue(a);
              this._sPastSelections = this._elTextbox.value;
              this._clearInterval();
              this.itemSelectEvent.fire(this, a, a._oResultData);
              this._toggleContainer(false);
          }
          

          we can see it's firing the selectEvent after updating the value, so the onchange will be using the new value. I tested and that looks like working, meaning triggering the onchange event triggers the validation as well with the correct value (the one from the list, not the partial one entered by the user) . I'm waiting for a few opinions on this but I don't mind contributing this back to git if you think that's a good idea.

          Guillaume DELORY added a comment - - edited I was investigating a bit more this issue, and what do you think about adding this at the auto-complete behavior: ac.itemSelectEvent.subscribe(function () { e.onchange(); }); in hudson-behavior.js#INPUT.auto-complete:688 IMHO, it makes sense to trigger the change event when an element is selected in the auto-complete list, since looking at the code of the yahoo auto-complete library: YAHOO.widget.AutoComplete. prototype ._selectItem = function (a) { this ._bItemSelected = true ; this ._updateValue(a); this ._sPastSelections = this ._elTextbox.value; this ._clearInterval(); this .itemSelectEvent.fire( this , a, a._oResultData); this ._toggleContainer( false ); } we can see it's firing the selectEvent after updating the value, so the onchange will be using the new value. I tested and that looks like working, meaning triggering the onchange event triggers the validation as well with the correct value (the one from the list, not the partial one entered by the user) . I'm waiting for a few opinions on this but I don't mind contributing this back to git if you think that's a good idea.

          Oh btw, it looks like it's fixing 37205 at the same time. I guess the selectItem event is also fired when we click, and since it's happening after the value this time the value is correct (the full selected one, not the partial one).

          I will deploy this custom version of Jenkins for a while see if that works fine.

          Guillaume DELORY added a comment - Oh btw, it looks like it's fixing 37205 at the same time. I guess the selectItem event is also fired when we click, and since it's happening after the value this time the value is correct (the full selected one, not the partial one). I will deploy this custom version of Jenkins for a while see if that works fine.

            Unassigned Unassigned
            gdelory Guillaume DELORY
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: