htmlform muliselect chosen: convert each list
authorRyan Lane <rlane@wikimedia.org>
Thu, 8 Aug 2013 08:11:46 +0000 (16:11 +0800)
committerRyan Lane <rlane@wikimedia.org>
Thu, 22 Aug 2013 17:27:53 +0000 (10:27 -0700)
This change converts each checkbox list input separately, rather
than converting all together into a single select input.

Change-Id: Iec6687f7105cdb38fb92785aaa4357babaef1b4f

resources/mediawiki/mediawiki.htmlform.js

index 77ceee4..8e764e1 100644 (file)
@@ -90,7 +90,7 @@
                $td = $( '<td>' ),
                $fieldLabelText = $( '<label>' ),
                $container;
-               if ( type === 'table' ) {
+               if ( type === 'tr' ) {
                        addMulti( $oldContainer, $td );
                        $container = $( '<tr>' );
                        $container.append( $td );
 
        if ( $( '.mw-chosen' ).length ) {
                mw.loader.using( 'jquery.chosen', function () {
-                       var $toConvert,
-                       $converted;
-                       $toConvert = $( 'table .mw-chosen' );
-                       if ( $toConvert.length ) {
-                               $converted = convertCheckboxesToMulti( $toConvert, 'table' );
+                       $( '.mw-chosen' ).each( function () {
+                               var type = this.nodeName.toLowerCase(),
+                                       $converted = convertCheckboxesToMulti( $( this ), type );
                                $converted.find( '.htmlform-chzn-select' ).chosen( { width: 'auto' } );
-                       }
-                       $toConvert = $( 'div .mw-chosen' );
-                       if ( $toConvert.length ) {
-                               $converted = convertCheckboxesToMulti( $toConvert, 'div' );
-                               $converted.find( '.htmlform-chzn-select' ).chosen( { width: 'auto' } );
-                       }
+                       } );
                } );
        }