Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

pre-selected/default option #46

Open
Dunc80 opened this issue Oct 9, 2018 · 1 comment
Open

pre-selected/default option #46

Dunc80 opened this issue Oct 9, 2018 · 1 comment

Comments

@Dunc80
Copy link

Dunc80 commented Oct 9, 2018

Is it possible to have a value pre-selected?

When I open a form with this widget on an "update" page I want it to already have the existing data showing, rather than being blank as it would be on the "create" page.

Please could someone advise me on how to achieve this?

I am passing the options to the widget as array $x

'clientOptions' => [ 'valueField' => 'id', 'labelField' => 'name', 'allowEmptyOption' => true, 'preload' => true, 'options'=> $x, ],

@patschwork
Copy link

patschwork commented Feb 3, 2019

Hi,

just had the same question:

Example:

use app\models\DbTable;

echo SelectizeTextInput::widget([
    'name' => 'tagsGlobal',
    'value' => '162,163',              // <----------------- Thats the IDs
	'loadUrl' => ['tag/listglobal2'],
    'clientOptions' => [
        'plugins' => ['remove_button'],
        'valueField' => 'id',
        'labelField' => 'name',
        'searchField' => ['name'],
        'create' => false,
        'preload' => true,
        'options' =>                                       // use options
            DbTable::find()
                ->select(['id','name'])
                ->where(['like', 'name', 'Dim'])
                ->all(),
        ],
    ]);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants