Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to include the softark\duallistbox\DualListbox widget in formwizard Step #9

Closed
vitalypark0555 opened this issue Dec 19, 2018 · 7 comments
Labels
question Further information is requested

Comments

@vitalypark0555
Copy link

vitalypark0555 commented Dec 19, 2018

Hello, I really liked your wrapper of smart wizard, however, I can't put object variables into 'options' when I use another widget inside of your one. I think it's important, cuz many other widgets require setting object variables into options array. Thanks beforehand.

[
    'model' => $hiringTeam,
    'title' => 'HIRING TEAM',
    'description' => 'Choose members of the selection committee',
    'formInfoText' => '',
    'fieldConfig' => [
        'only' => ['employee_ids'],
        'employee_ids' => [
            'widget' => \softark\duallistbox\DualListbox::className(),
            'options' => [
                'model' => $hiringTeam,
                'attribute' => $hiringTeam->employee_ids,
                'items' => $employees,
                'clientOptions' => [
                    'moveOnSelect' => true,
                    'selectedListLabel' => 'General Hiring Team',
                    'nonSelectedListLabel' => 'Hiring Team for this job',
                ],
            ],
        ],
    ],
],
@vitalypark0555 vitalypark0555 changed the title Objects parameters in options of inner widget Objects parameters in options of an inner widget Dec 19, 2018
@buttflattery
Copy link
Owner

buttflattery commented Dec 19, 2018

Hello @vitalypark0555 , are you talking about passing the $model to the widget you are using? if that is so you dont need to pass it as the formwizard uses ActiveForm and the model passed for the step will be used for the widget as in the example for using the DualListbox here with the ActiveForm is like below

echo $form->field($model, $attribute)->widget(DualListbox::className(),[
        'items' => $items,
        'options' => $options,
        'clientOptions' => [
            'moveOnSelect' => false,
            'selectedListLabel' => 'Selected Items',
            'nonSelectedListLabel' => 'Available Items',
        ],
    ]);

and the FormWizard Plugin does the starting part itself which is

echo $form->field($model, $attribute)

and the wiget and the options that you pass are then linked with the field using

->widget($widget,$options)

so you should pass them like

[
    'model' => $hiringTeam,
    'title' => 'HIRING TEAM',
    'description' => 'Choose members of the selection committee',
    'formInfoText' => '',
    'fieldConfig' => [
        'only' => ['employee_ids'],
        'employee_ids' => [
            'widget' => \softark\duallistbox\DualListbox::className(),
            'options' => [
                'items' => $employees,
                'clientOptions' => [
                    'moveOnSelect' => true,
                    'selectedListLabel' => 'General Hiring Team',
                    'nonSelectedListLabel' => 'Hiring Team for this job',
                ],
            ],
        ],
    ],
],

@buttflattery buttflattery added the question Further information is requested label Dec 19, 2018
@vitalypark0555
Copy link
Author

Hi buttflattery. Thanks for your response. I have tried different options, but nothing works.
I get error "htmlspecialchars() expects parameter 1 to be string, object given".

@buttflattery
Copy link
Owner

okay let me verify it i will reply soon i didnt tested the last code i sent, it would probably be some wrong configurations, the extension supports using any other widget within the steps, i will post back soon.

@buttflattery
Copy link
Owner

@vitalypark0555 it does work correctly without any problem see the image i get the following

image

when i use this config

'fieldConfig' => [
    'only' => ['tag_id'],
    'tag_id' => [
        'widget' => \softark\duallistbox\DualListbox::class,
        'options' => [
            'items' => ArrayHelper::map(Tags::find()->all(), 'id', 'name'),
            'clientOptions' => [
                'moveOnSelect' => true,
                'selectedListLabel' => 'General Hiring Team',
                'nonSelectedListLabel' => 'Hiring Team for this job'
            ]
        ]
    ]
]

You need to look into your items option for the DualListbox that you are passing you should pass them in key=>value pair. The array keys are option values, and the array values are the corresponding option labels.

@vitalypark0555
Copy link
Author

Buttflattery, thank you very much. It works like a charm.

@buttflattery
Copy link
Owner

@vitalypark0555 no problem you are welcome.

@vitalypark0555
Copy link
Author

Done!

@buttflattery buttflattery changed the title Objects parameters in options of an inner widget How to include the softark\duallistbox\DualListbox widget in formwizard Step Dec 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants