X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.htmlform.checker.js;h=674584b14a42bbc3f140e42d608967081f51597e;hb=dfec83932fd38a9086eb5a2e212889ad00f35b0e;hp=661a1c4b4786e5101d5fe5e712236491a4671d60;hpb=1c29f24dd5833ff2f990556291b5987b6b783e4e;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.htmlform.checker.js b/resources/src/mediawiki.htmlform.checker.js index 661a1c4b47..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,13 +110,13 @@ * @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; if ( errors.length === 0 ) { // FIXME: Use CSS transition - // eslint-disable-next-line jquery/no-slide + // eslint-disable-next-line no-jquery/no-slide $errorBox.slideUp( function () { $errorBox .removeAttr( 'class' ) @@ -163,17 +160,21 @@ .detach(); } // FIXME: Use CSS transition - // eslint-disable-next-line jquery/no-slide + // 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' ) ) { - // eslint-disable-next-line jquery/no-slide + 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 { showFunc();