2 * Simple mixin for text parameters. Should only be used within
3 * the apisandbox code, and for objects that have
4 * - a getValue function
5 * - a setValue function
6 * - a getValidity function
8 * - a setTitle function
9 * - this.paramInfo object set
15 function TextParamMixin() {
16 // This mixin does not manage state, nothing to do here
22 TextParamMixin.prototype.getApiValue = function () {
23 return this.getValue();
27 * @param {any|undefined} newValue
29 TextParamMixin.prototype.setApiValue = function ( newValue ) {
30 if ( newValue === undefined ) {
31 newValue = this.paramInfo.default;
33 this.setValue( newValue );
37 * Check if a text parameter is valid for the api, and if the result is not valid, set the icon
38 * to 'alert' and the title to a message explaining that the value is invalid. If shouldSuppressErrors
39 * is true, then the result of the validity check is always treated as valid.
41 * @param {boolean} shouldSuppressErrors
42 * @return {jQuery.Promise}
44 TextParamMixin.prototype.apiCheckValid = function ( shouldSuppressErrors ) {
45 return this.getValidity().then(
46 () => $.Deferred().resolve( true ).promise(),
47 () => $.Deferred().resolve( false ).promise()
49 ok = ok || shouldSuppressErrors;
50 this.setIcon( ok ? null : 'alert' );
51 this.setTitle( ok ? '' : mw.message( 'apisandbox-alert-field' ).plain() );
55 module.exports = TextParamMixin;