jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/370628 )
Change subject: Indicate recognized/unrecognized input in entityselector.
......................................................................
Indicate recognized/unrecognized input in entityselector.
- adds a css class to the input field depending on whether the input was
recognized or not
Bug: T170531
Change-Id: I0aabf65fc0234a0cd2071a3b9856df6b49d7ad6f
---
M view/resources/jquery/wikibase/jquery.wikibase.entityselector.js
M
view/resources/jquery/wikibase/themes/default/jquery.wikibase.entityselector.css
M view/tests/qunit/jquery/wikibase/jquery.wikibase.entityselector.tests.js
3 files changed, 66 insertions(+), 0 deletions(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/view/resources/jquery/wikibase/jquery.wikibase.entityselector.js
b/view/resources/jquery/wikibase/jquery.wikibase.entityselector.js
index 21b64b5..5835a9b 100644
--- a/view/resources/jquery/wikibase/jquery.wikibase.entityselector.js
+++ b/view/resources/jquery/wikibase/jquery.wikibase.entityselector.js
@@ -154,9 +154,35 @@
.off( 'blur' )
.on( 'eachchange.' + this.widgetName, function ( event
) {
self._search( event );
+ } )
+ .on( 'focusout', function () {
+ self._indicateRecognizedInput();
+ } )
+ .on( 'focusin', function () {
+ self._inEditMode();
} );
},
+ _indicateRecognizedInput: function () {
+ this._resetInputHighlighting();
+
+ if ( this._selectedEntity !== null ) {
+ this.element.addClass(
'ui-entityselector-input-recognized' );
+ } else if ( this.element.val() !== '' ) {
+ this.element.addClass(
'ui-entityselector-input-unrecognized' );
+ }
+ },
+
+ _inEditMode: function () {
+ this._resetInputHighlighting();
+ },
+
+ _resetInputHighlighting: function () {
+ this.element.removeClass(
+ 'ui-entityselector-input-recognized
ui-entityselector-input-unrecognized'
+ );
+ },
+
/**
* @inheritdoc
*/
diff --git
a/view/resources/jquery/wikibase/themes/default/jquery.wikibase.entityselector.css
b/view/resources/jquery/wikibase/themes/default/jquery.wikibase.entityselector.css
index 8f5a359..58d1c6f 100644
---
a/view/resources/jquery/wikibase/themes/default/jquery.wikibase.entityselector.css
+++
b/view/resources/jquery/wikibase/themes/default/jquery.wikibase.entityselector.css
@@ -69,3 +69,13 @@
text-align: right;
padding-right: 1.2em;
}
+
+.ui-entityselector-input-recognized {
+ /* NOTE: !important because valueview styles */
+ border-color: #14866d !important;
+}
+.ui-entityselector-input-unrecognized {
+ /* NOTE: !important because valueview styles */
+ background-color: #fee7e6 !important;
+ border-color: #b32424 !important;
+}
diff --git
a/view/tests/qunit/jquery/wikibase/jquery.wikibase.entityselector.tests.js
b/view/tests/qunit/jquery/wikibase/jquery.wikibase.entityselector.tests.js
index 909b4bb..a39199d 100644
--- a/view/tests/qunit/jquery/wikibase/jquery.wikibase.entityselector.tests.js
+++ b/view/tests/qunit/jquery/wikibase/jquery.wikibase.entityselector.tests.js
@@ -90,6 +90,36 @@
$entitySelector.trigger( 'eachchange.entityselector' );
} );
+ QUnit.test( 'Indicate unrecognized input', function ( assert ) {
+ var $entitySelector = newTestEntitySelector();
+ $entitySelector.data( 'entityselector' );
+
+ assert.notOk( $entitySelector.hasClass(
'ui-entityselector-input-unrecognized' ) );
+
+ $entitySelector.val( 'does-not-exist' );
+ $entitySelector.blur();
+ assert.ok( $entitySelector.hasClass(
'ui-entityselector-input-unrecognized' ) );
+ } );
+
+ QUnit.test( 'Indicate recognized input', function ( assert ) {
+ var done = assert.async(),
+ $entitySelector = newTestEntitySelector();
+
+ $entitySelector.data( 'entityselector' );
+
+ assert.notOk( $entitySelector.hasClass(
'ui-entityselector-input-recognized' ) );
+ $entitySelector.val( 'abc' );
+
+ $entitySelector
+ .one( 'entityselectorselected', function ( event, id ) {
+ $entitySelector.blur();
+ assert.ok( $entitySelector.hasClass(
'ui-entityselector-input-recognized' ) );
+ done();
+ } );
+
+ $entitySelector.trigger( 'eachchange.entityselector' );
+ } );
+
QUnit.test( 'Don\'t implicitly select entity by matching alias /
selectedEntity()', function ( assert ) {
QUnit.expect( 0 );
--
To view, visit https://gerrit.wikimedia.org/r/370628
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0aabf65fc0234a0cd2071a3b9856df6b49d7ad6f
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jakob <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits