jenkins-bot has submitted this change and it was merged.
Change subject: TextInputWidget: Add getValidity function
......................................................................
TextInputWidget: Add getValidity function
This method returns a promise that resolves if the field is valid and
rejects if not. Helpful when you need to check the validity of multiple
fields with a single $.when call.
Bug: T99831
Bug: T107998
Change-Id: I9a027033cb4253b211a91ecb7baf22046bcb7213
---
M src/widgets/TextInputWidget.js
1 file changed, 45 insertions(+), 0 deletions(-)
Approvals:
Alex Monk: Looks good to me, approved
Jforrester: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/src/widgets/TextInputWidget.js b/src/widgets/TextInputWidget.js
index 6ef8734..6b39a64 100644
--- a/src/widgets/TextInputWidget.js
+++ b/src/widgets/TextInputWidget.js
@@ -509,6 +509,7 @@
* This method returns a promise that resolves with a boolean `true` if the
current value is
* considered valid according to the supplied {@link #validate validation
pattern}.
*
+ * @deprecated
* @return {jQuery.Promise} A promise that resolves to a boolean `true` if the
value is valid.
*/
OO.ui.TextInputWidget.prototype.isValid = function () {
@@ -525,6 +526,50 @@
};
/**
+ * Get the validity of current value.
+ *
+ * This method returns a promise that resolves if the value is valid and
rejects if
+ * it isn't. Uses the {@link #validate validation pattern} to check for
validity.
+ *
+ * @return {jQuery.Promise} A promise that resolves if the value is valid,
rejects if not.
+ */
+OO.ui.TextInputWidget.prototype.getValidity = function () {
+ var result, promise;
+
+ function rejectOrResolve( valid ) {
+ if ( valid ) {
+ return $.Deferred().resolve().promise();
+ } else {
+ return $.Deferred().reject().promise();
+ }
+ }
+
+ if ( this.validate instanceof Function ) {
+ result = this.validate( this.getValue() );
+
+ if ( $.isFunction( result.promise ) ) {
+ promise = $.Deferred();
+
+ result.then( function ( valid ) {
+ if ( valid ) {
+ promise.resolve();
+ } else {
+ promise.reject();
+ }
+ }, function () {
+ promise.reject();
+ } );
+
+ return promise.promise();
+ } else {
+ return rejectOrResolve( result );
+ }
+ } else {
+ return rejectOrResolve( this.getValue().match( this.validate )
);
+ }
+};
+
+/**
* Set the position of the inline label relative to that of the value:
`‘before’` or `‘after’`.
*
* @param {string} labelPosition Label position, 'before' or 'after'
--
To view, visit https://gerrit.wikimedia.org/r/229336
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9a027033cb4253b211a91ecb7baf22046bcb7213
Gerrit-PatchSet: 5
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Prtksxna <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Mooeypoo <[email protected]>
Gerrit-Reviewer: Prtksxna <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits