$textAttribs = array(
'id' => $this->mID . '-other',
'size' => $this->getSize(),
+ 'class' => array( 'mw-htmlform-select-and-other-field' ),
+ 'data-id-select' => $this->mID,
);
if ( $this->mClass !== '' ) {
- $textAttribs['class'] = $this->mClass;
+ $textAttribs['class'][] = $this->mClass;
}
$allowedParams = array(
'autofocus',
'multiple',
'disabled',
- 'tabindex'
+ 'tabindex',
+ 'maxlength', // gets dynamic with javascript, see mediawiki.htmlform.js
);
$textAttribs += $this->getAttributes( $allowedParams );
$list = $request->getText( $this->mName );
$text = $request->getText( $this->mName . '-other' );
+ // Should be built the same as in mediawiki.htmlform.js
if ( $list == 'other' ) {
$final = $text;
} elseif ( !in_array( $list, $this->mFlatOptions, true ) ) {
'scripts' => 'resources/src/mediawiki/mediawiki.htmlform.js',
'dependencies' => array(
'jquery.mwExtension',
+ 'jquery.byteLimit',
+ ),
+ 'messages' => array(
+ 'htmlform-chosen-placeholder',
+ // @todo Load this message in content language
+ 'colon-separator',
),
- 'messages' => array( 'htmlform-chosen-placeholder' ),
),
'mediawiki.icon' => array(
'styles' => 'resources/src/mediawiki/mediawiki.icon.less',
} );
function enhance( $root ) {
- var $matrixTooltips, $autocomplete;
+ var $matrixTooltips, $autocomplete,
+ // cache the separator to avoid object creation on each keypress
+ colonSeparator = mw.message( 'colon-separator' ).text();
/**
* @ignore
handleSelectOrOther.call( this, true );
} );
+ // Add a dynamic max length to the reason field of SelectAndOther
+ // This checks the length together with the value from the select field
+ // When the reason list is changed and the bytelimit is longer than the allowed,
+ // nothing is done
+ $root
+ .find( '.mw-htmlform-select-and-other-field' )
+ .each( function () {
+ var $this = $( this ),
+ // find the reason list
+ $reasonList = $root.find( '#' + $this.data( 'id-select' ) ),
+ // cache the current selection to avoid expensive lookup
+ currentValReasonList = $reasonList.val();
+
+ $reasonList.change( function () {
+ currentValReasonList = $reasonList.val();
+ } );
+
+ $this.byteLimit( function ( input ) {
+ // Should be built the same as in HTMLSelectAndOtherField::loadDataFromRequest
+ var comment = currentValReasonList;
+ if ( comment === 'other' ) {
+ comment = input;
+ } else if ( input !== '' ) {
+ // Entry from drop down menu + additional comment
+ comment += colonSeparator + input;
+ }
+ return comment;
+ } );
+ } );
+
// Set up hide-if elements
$root.find( '.mw-htmlform-hide-if' ).each( function () {
var v, $fields, test, func,