根据其他字段的值显示/隐藏字段

时间:2020-06-20 04:01:37

标签: laravel backpack-for-laravel laravel-backpack

我有一个场景,其中一个字段应基于另一个字段的值显示为下拉列表或文本字段。

示例:

如果所选国家/地区为美国,则用户可以选择州作为下拉列表(加利福尼亚,北卡罗来纳州等)。

如果选择了其他任何国家(美国以外的国家),则仅向用户显示可编辑的文本字段(而不是下拉菜单)。

请让我知道是否有一种方法可以使用背包的开箱即用功能。如果没有,是否有任何解决方法?

我的代码段:

数据库中的国家/地区:

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)
]);

0 个答案:

没有答案
相关问题