Показать / скрыть поля на основе значения другого поля - PullRequest
0 голосов
/ 20 июня 2020

У меня есть сценарий, в котором поле должно отображаться как раскрывающееся или текстовое поле в зависимости от значения другого поля.

Пример:

Пользователь для выбора состояния как раскрывающийся список (Калифорния, Северная Каролина и т. д. c), если выбранная страна - США.

Если выбрана любая другая страна (кроме США), пользователю должно быть показано только редактируемое текстовое поле (вместо раскрывающийся список).

Сообщите мне, есть ли способ добиться этого, используя готовые к использованию функции рюкзака. Если нет, возможно ли какое-либо решение?

Мой фрагмент кода:

СТРАНА ПОЛЕ ИЗ БД:

CRUD::addField([
       // 1-n relationship
       'name'      => 'countryid', // the column that contains the ID of that connected entity;
       'label'     => 'Country', // Table column heading
       'type'      => 'select2',
       'entity'    => 'getcountryid', // the method that defines the relationship in your Model
       // optional
       //'attribute' => 'name', // foreign key attribute that is shown to user
       'model'     => "App\Models\Country", // foreign key model
    ]); 

ГОСУДАРСТВЕННОЕ ПОЛЕ ЧТО ЗАВИСИТ ОТ ПОЛЯ СТРАНЫ ( ЭТО ДОЛЖНО БЫТЬ СДЕЛАНО В КАЧЕСТВЕ ТЕКСТА ИЛИ ЗАПИСИ НА ОСНОВЕ ВЫБРАННОЙ СТРАНЫ ):

CRUD::addField([ // select2_from_ajax: 1-n relationship
'label'                => "State", // Table column heading
'type'                 => 'select2_from_ajax',
'name'                 => 'countrystateid', // the column that contains the ID of that connected entity;
'entity'               => 'countrystate', // the method that defines the relationship in your Model
'attribute'            => 'name', // foreign key attribute that is shown to user
'data_source'          => url('/api/countrystate'), // url to controller search function (with /{id} should return model)
'placeholder'          => 'Select an Indian state', // placeholder for the select
'minimum_input_length' => 0, // minimum characters to type before querying results
'dependencies'         => ['countryid'], // when a dependency changes, this select2 is reset to null
//'method'                    => 'GET', // optional - HTTP method to use for the AJAX call ]); (GET, POST)
]);
...