2 * HTMLForm enhancements:
3 * Add a dynamic max length to the reason field of SelectAndOther.
7 // cache the separator to avoid object creation on each keypress
8 var colonSeparator
= mw
.message( 'colon-separator' ).text();
10 mw
.hook( 'htmlform.enhance' ).add( function ( $root
) {
11 // This checks the length together with the value from the select field
12 // When the reason list is changed and the bytelimit is longer than the allowed,
15 .find( '.mw-htmlform-select-and-other-field' )
17 var $this = $( this ),
18 // find the reason list
19 $reasonList
= $root
.find( '#' + $this.data( 'id-select' ) ),
20 // cache the current selection to avoid expensive lookup
21 currentValReasonList
= $reasonList
.val();
23 $reasonList
.change( function () {
24 currentValReasonList
= $reasonList
.val();
27 $this.byteLimit( function ( input
) {
28 // Should be built the same as in HTMLSelectAndOtherField::loadDataFromRequest
29 var comment
= currentValReasonList
;
30 if ( comment
=== 'other' ) {
32 } else if ( input
!== '' ) {
33 // Entry from drop down menu + additional comment
34 comment
+= colonSeparator
+ input
;
41 }( mediaWiki
, jQuery
) );