yii-joblo / multimodelform

Yii extension multimodelform
13 stars 9 forks source link

ComboBox support #3

Closed uniconstructor closed 11 years ago

uniconstructor commented 11 years ago

Here is a combobox widget support. ( yiiframework.com/extension/combobox )

In my application I use a Toph's fork of combobox: github.com/kanyuga/yii-combobox (because this fork supports key=>value separation).

But it shoud work with main branch too (not tested).

Combobox plugin needs a small bugfix to work with multimodelform ( see my comment here: yiiframework.com/extension/combobox#c12257 )

Here is the code:

/**
 * Support for EJuiComboBox
 * 
 * @contributor Smirnov Ilya php1602agregator[at]gmail.com
 * @param array $element
 * @param bool  $allowText
 * @return string
 */
public static function afterNewIdComboBox($element, $allowText=true)
{
    $options = array();
    if ( $allowText )
    {
        $options['allowText'] = true;
    }

    $jsOptions = CJavaScript::encode($options);

    return "if ( this.attr('type') == 'text' && this.hasClass('ui-autocomplete-input') ) 
        {
            var mmfComboBoxParent   = this.parent();
            // cloning autocomplete and select elements (without data and events)
            var mmfComboBoxClone    = this.clone();
            var mmfComboSelectClone = this.prev().clone();

            // removing old combobox
            mmfComboBoxParent.empty();
            // addind new cloden elements ()
            mmfComboBoxParent.append(mmfComboSelectClone);
            mmfComboBoxParent.append(mmfComboBoxClone);

            // re-init autocomplete with default options
            mmfComboBoxClone.combobox({$jsOptions});
        }

        if ( this.attr('type') == 'button' )
        {// removing old combobox button
            this.remove();
        }";
}
yii-joblo commented 11 years ago

Added