简体   繁体   中英

How to set default values in Yii2 kartik\tree\TreeViewInput

I used kartik\\tree\\TreeViewInput in my project but in update form I can't display current selected values in treeview input!

I tried some thing like this based on documentation:

<?=  $form->field($model, 'tags')->widget(\kartik\tree\TreeViewInput::className(),[
                                                    'name' => 'tags',
                                                    'query' => Tags::find()->addOrderBy('root, lft'),
                                                    'value' => 1,
                                                    'headingOptions' => ['label' => 'tags'],
                                                    'rootOptions' => ['label'=>'<i class="fa fa-building"></i>'],
                                                    'fontAwesome' => true,
                                                    'asDropdown' => true,
                                                    'multiple' => true,
                                                    'options' => ['disabled' => false]
                                                ]);   ?>

But it doesn't display tag with (id='1')! How should I display values?

Use:

 'displayValue' => 1,

to auto display a node with id = 1 on the form.

If you do not want any node to be auto displayed use:

'displayValue' => 0,

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