From af4b453dd7aca7e163f9689ea8a4368e4a764155 Mon Sep 17 00:00:00 2001 From: theopolisme Date: Mon, 18 Nov 2013 17:14:09 -0600 Subject: [PATCH] Supress native "invalid email" warning on Special:ChangeEmail To avoid a double "invalid email" warning (one from the browser, one from updateMailValidityLabel), prevent the browser's "invalid email" notice from appearing and just run updateMailValidityLabel, which generates its own notice. Bug: 40909 Change-Id: Id657c6ce2e72d877510fcf690aef2c548d8cdf1d --- .../mediawiki.special.changeemail.js | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/resources/mediawiki.special/mediawiki.special.changeemail.js b/resources/mediawiki.special/mediawiki.special.changeemail.js index 2d22bad059..bc2a0a2688 100644 --- a/resources/mediawiki.special/mediawiki.special.changeemail.js +++ b/resources/mediawiki.special/mediawiki.special.changeemail.js @@ -9,6 +9,12 @@ var isValid = mw.util.validateEmail( mail ), $label = $( '#mw-emailaddress-validity' ); + // Set up the validity notice if it doesn't already exist + if ( $label.length === 0 ) { + $label = $( '' ) + .insertAfter( '#wpNewEmail' ); + } + // We allow empty address if ( isValid === null ) { $label.text( '' ).removeClass( 'valid invalid' ); @@ -24,19 +30,22 @@ } $( function () { - // Lame tip to let user know if its email is valid. See bug 22449. - // Only bind once for 'blur' so that the user can fill it in without errors; - // after that, look at every keypress for immediate feedback. - $( '#wpNewEmail' ).one( 'blur', function () { - var $this = $( this ); - if ( $( '#mw-emailaddress-validity' ).length === 0 ) { - $this.after( '' ); - } - - updateMailValidityLabel( $this.val() ); - $this.keyup( function () { + $( '#wpNewEmail' ) + // Lame tip to let user know if its email is valid. See bug 22449. + // Only bind once for 'blur' so that the user can fill it in without errors; + // after that, look at every keypress for immediate feedback. + .one( 'blur', function () { + var $this = $( this ); updateMailValidityLabel( $this.val() ); + $this.keyup( function () { + updateMailValidityLabel( $this.val() ); + } ); + } ) + // Supress built-in validation notice and just call updateMailValidityLabel(), + // to avoid double notice. See bug 40909. + .on( 'invalid', function ( e ) { + e.preventDefault(); + updateMailValidityLabel( $( this ).val() ); } ); - } ); } ); }( mediaWiki, jQuery ) ); -- 2.20.1