buttflattery / yii2-formwizard

A Yii2 plugin used for creating stepped form or form wizard using yii\widgets\ActiveForm and \yii\db\ActiveRecord
https://yii2plugins.omaraslam.com/formwizard
Other
96 stars 13 forks source link

Multiple models attributes with similar names #53

Closed Ediphonce closed 4 years ago

Ediphonce commented 4 years ago

I would like to utilize the multiple models feature, but my models has attributes with similar names ( model_one.name and model_two.name) , how can I reference them. I tried hiding one of them by using the code below but it is not working. 'model_two.name' => false,

here is the full code: [ 'model' => [$model_one,$model_two], 'title' => 'Project Details', 'description' => 'Enter Project Details', 'formInfoText' => '', 'fieldConfig' => [ 'created_at' => false, 'updated_at' => false, 'budget' => false, 'currency' => false, 'model_two.name' => false, 'name' => [ 'widget' => Select2::classname(), 'options' => [ 'data' => ArrayHelper::map(Partner::find()->all(), 'id', 'name'), 'language' => 'sw', 'options' => ['placeholder' => 'Select Partner...'], 'pluginOptions' => [ 'allowClear' => true ], ] ], ], ],

buttflattery commented 4 years ago

Hmm.. i dont think i have handled this scenario, give me a day and i will test and add a fix for this. currently there aint no support of providing the column names for the steps with the table names.

Ediphonce commented 4 years ago

Thank you @buttflattery for quick response, I'am looking forward for the fix.

buttflattery commented 4 years ago

Hello @Ediphonce i have added the support for using multi model steps with similar fields in the new release 1.6.8 you can run composer update to update the widget to the latest version and then you can prefix the field names with the model name, the widget uses $model->formName() method so be careful if you have overridden the formName() function in your model then use the relevant name.

See an example below where you need to use the Book and User model both in one step and you have the name field in both the tables/models.

'fieldConfig'=>[
    'user.name'=>[
        'options'=>[
            'class'=>'my-class',
            'placeholder'=>'Enter User Name'
        ]
    ],
    'book.name'=>[
        'options'=>[
            'class'=>'my-class'
            'placeholder'=>'Enter Book Name'
        ]
    ],
 ]

You can close the issue if you dont run into any problems.

Ediphonce commented 4 years ago

Hi @buttflattery, thank you for the update it is working, I appreciate your great work.

buttflattery commented 4 years ago

@Ediphonce you are welcome