extension multimodelform : about getMultiModelForm()

I like extension multimodelform and I am newbie, how to make getmultimodel() in model?, and how to write code in _form.php for this method

I have create this code, just don’t know is right or wrong?

==============================================================================================

public function getMultiModelForm()

    {


        $memberFormConfig = array(


            'elements'=>array(


                'alamat'=>array(


                    'type'=>'text',


                    'maxlength'=>40,


                ),


                'rt'=>array(


                    'type'=>'text',


                    'maxlength'=>40,


                ),





            ));


         $this->widget('ext.multimodelform.MultiModelForm',array(


            'id'=>'id_member',


            'formConfig'=>$memberFormConfig,


            'model'=>$model2,


            'validatedItems'=>$validatedMembers,


            'data'=>$model2->findAll('client_id=:client_id',array(':client_id'=>$model->id)),


        ));


    }

==================================================================================================

I assume you have added the public function ‘getMultiModelForm’ to your model2.

But you did not return the result of the function and did not assign the result to the ‘model’ property in the view.





class model2 ...

{


       public function getMultiModelForm()

        {

            return array(

                'elements'=>array(

                    'alamat'=>array(

                        'type'=>'text',

                        'maxlength'=>40,

                    ),

                    'rt'=>array(

                        'type'=>'text',

                        'maxlength'=>40,

                    ),


                ));

...


}




And in the view you don’t have to build the configArray, only call the method getMultiModelForm() of model2.





 $this->widget('ext.multimodelform.MultiModelForm',array(

                'id'=>'id_member',

                'formConfig'=>$model2->getMultiModelForm(),

                'model'=>$model2,

                'validatedItems'=>$validatedMembers,

                'data'=>$model2->findAll('client_id=:client_id',array(':client_id'=>$model->id)),

            ));




There is no ‘magic’.

The only difference to the extension example is, that you don’t define the configuration array for ‘formConfig’ in the view.

You define it in the code of model2 where you better can see what attributes and rules to use …

("The model2 better knows, how to build the formConfig than the view").

You can choose other function names like ‘getForm()’,‘getFormConfig()’ … or whatever you like.

This has nothing to do with the extension itself.

thank for your explanation, it SOLVED my problem, but just my newbie curious is what for $validatedMembers, for me it seem vital but in the declare variable is jut empty array, are this have to exist because to fulfill validatedItems?

When the form is displayed before validation, the validatedMembers are empty.

After submitting the models are validated in the controllers create/update action.

If there are validation errors, the form is called again and the validatedMembers are populated with all validated models.

Transfer the validateMembers to the form view after validation is important to keep all previous input (at this moment the new data are not saved to the db) and to show the errors to the user.

hi,

I am still work in multimodelform, and now I want to place calendar in $model2, but I can’t place it.

this my code in model2.php




public function getMultiModelForm()

        {

            return array(

                'elements'=>array(

                     'date_birth' => array(

                           $this->widget('zii.widgets.jui.CJuiDatePicker', array(

                                  'name'=>'date_birth',

                                  // additional javascript options for the date picker plugin

                                  'options'=>array(

                                  'showAnim'=>'fold',

                                  ),

                                  'htmlOptions'=>array(

                                  'style'=>'height:20px;'

                                  ),

                               ));

                        )

                   );



What I can tell you, this is not work all, the error is $this-widget (‘zii.widgets.jui.CJuiDatePicker’ is undefine,

what the right code? and also how to shape the form in model2 became gridview? I have try just insert like this and it can’t.

I have released v2.0 of multimodelform which now handles both your feature requests:

  • tableview

  • cloning CJuiDatePicker

Please take a look at the documentation there.

Hi Joblo, I have try ver 2.1, but I have to say, this version more confuse me.

  1. CJuiDatePicker:

    I have try follow your tutorial, include add this




$this->widget('ext.multimodelform.MultiModelForm',array(

       ...

         // 'jsBeforeNewId' => "alert(this.attr('id'));", 

        'jsAfterNewId' => MultiModelForm::afterNewIdDatePicker($formConfig['elements']['dayofbirth']),

       ...

    ));



but nothing happend, not like version 1.0.2, it just add widget and not add above code, and is good running.

  1. about id[PK], client_id[FK] field all is show up, how I hidden this field, I use ‘type’=>‘hidden’ not work, in version 1.02, just not write it and it is not show up.

  2. what the mean bugfixed in detail record create twice at version 1.02, because I input data in the form profile client just insert 1 record.

  3. in this version 2.1, can I steel use the public function getMultiModelForm() at model and how add in




jsAfterNewId' => MultiModelForm::afterNewIdDatePicker($formConfig['elements']['dayofbirth'])



I use yii 1.1.7, thanks