From: theopolisme Date: Mon, 18 Nov 2013 23:14:09 +0000 (-0600) Subject: Supress native "invalid email" warning on Special:ChangeEmail X-Git-Tag: 1.31.0-rc.0~17983^2 X-Git-Url: http://git.cyclocoop.org/%22.htmlspecialchars%28%24url_syndic%29.%22?a=commitdiff_plain;h=af4b453dd7aca7e163f9689ea8a4368e4a764155;p=lhc%2Fweb%2Fwiklou.git 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 --- 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 ) );