简体   繁体   中英

how to integrate multimodelform with echmultiselect yii?

I am running into a little snag with combining extensions "EchMultiSelect" and "MultiModelForm" of YII framework.

What I'm trying to do is copy a set of form elements one of which elements is an EchMultiSelect widget.

According to tutorial on the jqRelCopy page, I would need to pass a copy of the element (datePicker in their example) to the 'jsAfterNewId' option:

'jsAfterNewId' => JQRelcopy::afterNewIdDatePicker($datePickerConfig),

So, I tried to modify that to:

'jsAfterNewId' => MultiModelForm::afterNewIdMultiSelect($memberFormConfig['elements']),

Where I also added the following to MultiModelForm.php:

public static function afterNewIdMultiSelect($element)
    {
            $options = isset($element['options']) ? $element['options'] : array();
            $jsOptions = CJavaScript::encode($options);
            return "if(this.attr('multiple')=='multiple'){this.multiselect(jQuery.extend({$jsOptions}));};";                
    }

its copied and working properly when i am using Add Person link but what happens if i am adding/cloning three items for example and when i change the third item multiselct option then its reflecting to the first multiselect dropdown only this is same for other as well also when i am adding new items by clicking on the Add Person link then its cloning the same element to the new row item

here is the code for the form configuration variables and multimodel widget call.

//$userList=array of the userIds from users table
$memberFormConfig = array(
      'elements'=>array(
        'userId'=>array(
            'type'=>'ext.EchMultiSelect.EchMultiSelect',                
            'model' => $User,
            'dropDownAttribute' => 'userId', 
            'data' => $userList,
            'dropDownHtmlOptions'=> array(
                'style'=>'width:500px;',
            ),
        ),
        ...
        ...         
    ));

calling the MultiModelForm widget from the same view file

$this->widget('ext.multimodelform.MultiModelForm',array(
        'id' => 'id_member', //the unique widget id
        'formConfig' => $memberFormConfig, //the form configuration array
        'model' => $model, //instance of the form model
        'tableView' => true,
        'validatedItems' => $validatedMembers,
        'data' => Person::model()->findAll('userId=:userId', array(':userId'=>$model->id)),
        'addItemText' => 'Add Person',
        'showAddItemOnError' => false, //not allow add items when in validation error mode (default = true)
             'fieldsetWrapper' => array('tag' => 'div',
            'htmlOptions' => array('class' => 'view','style'=>'position:relative;background:#EFEFEF;')
        ),
        'removeLinkWrapper' => array('tag' => 'div',
            'htmlOptions' => array('style'=>'position:absolute; top:1em; right:1em;')
        ),

        'jsAfterNewId' => MultiModelForm::afterNewIdMultiSelect($memberFormConfig['elements']),
    ));

Can someone help me with this please?

Thanks in advance!

After a long searching and googleing i found the solution for this, just replace the function in your MultiModelForm.php:

public static function afterNewIdMultiSelect($element)
{
      $options = isset($element['options']) ? $element['options'] : array();
      $jsOptions = CJavaScript::encode($options);
      return "if ( this.hasClass('test123456') )
        {
            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.multiselect(jQuery.extend({$jsOptions}));
        }";
}

Thats It....!!

Thanks...!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM