jenkins-bot has submitted this change and it was merged.
Change subject: entityselector: Properly set value when selecting a suggestion
......................................................................
entityselector: Properly set value when selecting a suggestion
Setting the actual input element's value when selecting a suggestion to prevent
a reset via validateInput() which is issued via the blur event handler.
Change-Id: I9dcb711b049df4d252cb4165aec80f727477e13f
---
M lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
1 file changed, 15 insertions(+), 22 deletions(-)
Approvals:
Tobias Gritschacher: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
b/lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
index 10cd9a8..dad5796 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
@@ -232,29 +232,16 @@
// is set already.
this.menu.element.on( 'mousedown.' + this.widgetName,
function( event ) {
if ( $( event.target ).closest(
'.ui-menu-item:not( .ui-suggester-custom )' ).length ) {
- var item =
- $( event.target ).closest(
'.ui-menu-item' ).data( 'item.autocomplete' );
+ var $item = $( event.target ).closest(
'.ui-menu-item' ),
+ item = $item.data(
'item.autocomplete' );
+
+ self.element.val( item.value || item.id
);
self._setEntity( item );
if ( self.options.emulateSearchBox ) {
window.location.href = item.url;
}
-
}
- } );
-
- // When focusing a menu item, replace the input value
with entity id if the entity has
- // no label.
- var fnNativeMenuFocus = this.menu.option( 'focus' );
- this.menu.option( 'focus', function( event, ui ) {
- fnNativeMenuFocus( event, ui );
-
- var item = ui.item.data( 'item.autocomplete' );
- if ( !item.value && /^(mouse|key)/.test(
event.originalEvent.type ) ) {
- self.element.val( ui.item.data(
'item.autocomplete' ).id );
- }
-
- self._setEntity( item );
} );
// Prevent native menu selected callback to alter the
input value when the "selected"
@@ -392,7 +379,7 @@
*/
more: function() {
this._continueSearch = true;
- this.search();
+ this.search( this._term );
this._continueSearch = false;
},
@@ -407,6 +394,12 @@
initialOffset = this.offset;
if ( searchTerm === this.element.val() ) {
+ // Reset this.term to the actual search
term. Native jquery.autocomplete
+ // sets this.term to this.element.val()
in search(). Auto-completing the string
+ // to the first search hit's label
results in setting this.term to the whole
+ // label.
+ this.term = searchTerm;
+
// clear cached results
if ( !this._cache ||
!this._cache[searchTerm] || this.offset === 0 ) {
this._cache = {};
@@ -433,11 +426,8 @@
response.search.length > 0
// Do not auto-complete when
hitting backspace due to API lag.
&& this._lastKeyDown !==
$.ui.keyCode.BACKSPACE
- // Do not auto-complete when
fetching more results since it would trigger
- // another API call.
- && initialOffset === 0
) {
- var firstMatch =
response.search[0],
+ var firstMatch =
this._cache[searchTerm][0],
stringToAutocomplete =
firstMatch.label || '';
// Aliases array is returned
only when there is a search hit on an alias.
@@ -462,6 +452,9 @@
&& (
!this.selectedEntity() || this.selectedEntity().id !== firstMatch.id
)
+ // Do not select when
fetching more results since it would trigger
+ // another API call.
+ && initialOffset === 0
) {
this._setEntity(
firstMatch );
// Not triggering event
via this._updateValue() because having
--
To view, visit https://gerrit.wikimedia.org/r/90313
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9dcb711b049df4d252cb4165aec80f727477e13f
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits