X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.htmlform.checker.js;h=674584b14a42bbc3f140e42d608967081f51597e;hp=78e9f5f6acafcc3b4044fcc8a2c083f3a8344adb;hb=04d1aa3033f40a38d721f7f0e88b5bac440d2869;hpb=bf6bca499145d513a76140f6ee2df4f92f3ed397 diff --git a/resources/src/mediawiki.htmlform.checker.js b/resources/src/mediawiki.htmlform.checker.js index 78e9f5f6ac..674584b14a 100644 --- a/resources/src/mediawiki.htmlform.checker.js +++ b/resources/src/mediawiki.htmlform.checker.js @@ -73,7 +73,7 @@ if ( value === '' ) { this.currentValue = value; - this.setErrors( [] ); + this.setErrors( true, [] ); return; } @@ -91,14 +91,10 @@ that.currentValue = value; - if ( info.valid ) { - that.setErrors( [], forceReplacement ); - } else { - that.setErrors( info.messages, forceReplacement ); - } + that.setErrors( info.valid, info.messages, forceReplacement ); } ).fail( function () { that.currentValue = null; - that.setErrors( [] ); + that.setErrors( true, [] ); } ); return currentRequestInternal; @@ -106,6 +102,7 @@ /** * Display errors associated with the form element + * @param {boolean} valid Whether the input is still valid regardless of the messages * @param {Array} errors Error messages. Each error message will be appended to a * `` or `
  • `, as with jQuery.append(). * @param {boolean} [forceReplacement] Set true to force a visual replacement even @@ -113,7 +110,7 @@ * @return {mw.htmlform.Checker} * @chainable */ - mw.htmlform.Checker.prototype.setErrors = function ( errors, forceReplacement ) { + mw.htmlform.Checker.prototype.setErrors = function ( valid, errors, forceReplacement ) { var $oldErrorBox, tagName, showFunc, text, replace, $errorBox = this.$errorBox; @@ -165,14 +162,18 @@ // FIXME: Use CSS transition // eslint-disable-next-line no-jquery/no-slide $errorBox - .attr( 'class', 'error' ) + .attr( 'class', valid ? 'warning' : 'error' ) .empty() .append( errors.map( function ( e ) { return errors.length === 1 ? e : $( '
  • ' ).append( e ); } ) ) .slideDown(); }; - if ( $oldErrorBox !== $errorBox && $oldErrorBox.hasClass( 'error' ) ) { + if ( + $oldErrorBox !== $errorBox && + // eslint-disable-next-line no-jquery/no-class-state + ( $oldErrorBox.hasClass( 'error' ) || $oldErrorBox.hasClass( 'warning' ) ) + ) { // eslint-disable-next-line no-jquery/no-slide $oldErrorBox.slideUp( showFunc ); } else {