敏捷工具包 atk4 php 在不提交表单的情况下根据另一个字段值设置字段值
Agile toolkit atk4 php set field value based on anther field value without submitting the form
I am using agile toolkit code for developing an application , i do have dropdown that get values from database, I want to show selected value from field 1 to field 2 without submit any thing.
$form->addField('field1', ['caption' => 'Field 1', 'DropDown', 'values'=> $arra1,'isMultiple' => 真,'readonly' => 假,['dropdownOptions' => ['fullTextSearch' => 真]]]);
$form->addField('field2', ['caption' => 'Select Specfic Values', 'DropDown','model' => 新建 view_values ($db),'dependency' => 函数 (view_values $model, $data)
{isset($数据['field1']) ? $model->addCondition($model->fieldName()->id, 'like', '%' . $data['field1'] . '%') : null;}
,'isMultiple' => 真 ,'readonly' => 假, ['dropdownOptions' => ['fullTextSearch' => 真]]]);
问题是致命错误 atk4\ui\Exception:无法添加表单字段 (),对象:atk4\ui\FormField\DropDown () 属性:“依赖项”值:{}。寻求帮助。也许我的逻辑是错误的。
I have managed to find a solution for 2 field multi selection scenario:
$values = new view_table($db);
$values->addCondition($db->dsql()->orExpr()->where($db->dsql()->
andExpr()->where('field_status','<>','1')));
$Array = array();
reset($Array);
foreach($values as $row){
$Array[$row['id']] = $row['field_1'].": ".$row['field_2'];
}
$fieldvalue_1 = $form->addField('fieldvalue_1', ['caption' => 'fieldvalue_1', 'DropDown', 'values'=> $Array,'isMultiple' => true ,'readonly' => $readonly, ['dropdownOptions' => ['fullTextSearch' => true]]]);
$fieldvalue_2 = $form->addField('fieldvalue_2', ['caption' => 'fieldvalue_2', 'DropDown', 'values'=> $Array,'isMultiple' => true ,'readonly' => $readonly, ['dropdownOptions' => ['fullTextSearch' => true]]])->set($_GET['val'] ?? 'No value');
$fieldvalue_1->js('change' ,new \atk4\ui\JsReload($fieldvalue_2,['val' => $fieldvalue_1->jsInput()->val()]));
I am using agile toolkit code for developing an application , i do have dropdown that get values from database, I want to show selected value from field 1 to field 2 without submit any thing.
$form->addField('field1', ['caption' => 'Field 1', 'DropDown', 'values'=> $arra1,'isMultiple' => 真,'readonly' => 假,['dropdownOptions' => ['fullTextSearch' => 真]]]);
$form->addField('field2', ['caption' => 'Select Specfic Values', 'DropDown','model' => 新建 view_values ($db),'dependency' => 函数 (view_values $model, $data) {isset($数据['field1']) ? $model->addCondition($model->fieldName()->id, 'like', '%' . $data['field1'] . '%') : null;} ,'isMultiple' => 真 ,'readonly' => 假, ['dropdownOptions' => ['fullTextSearch' => 真]]]);
问题是致命错误 atk4\ui\Exception:无法添加表单字段 (),对象:atk4\ui\FormField\DropDown () 属性:“依赖项”值:{}。寻求帮助。也许我的逻辑是错误的。
I have managed to find a solution for 2 field multi selection scenario:
$values = new view_table($db);
$values->addCondition($db->dsql()->orExpr()->where($db->dsql()->
andExpr()->where('field_status','<>','1')));
$Array = array();
reset($Array);
foreach($values as $row){
$Array[$row['id']] = $row['field_1'].": ".$row['field_2'];
}
$fieldvalue_1 = $form->addField('fieldvalue_1', ['caption' => 'fieldvalue_1', 'DropDown', 'values'=> $Array,'isMultiple' => true ,'readonly' => $readonly, ['dropdownOptions' => ['fullTextSearch' => true]]]);
$fieldvalue_2 = $form->addField('fieldvalue_2', ['caption' => 'fieldvalue_2', 'DropDown', 'values'=> $Array,'isMultiple' => true ,'readonly' => $readonly, ['dropdownOptions' => ['fullTextSearch' => true]]])->set($_GET['val'] ?? 'No value');
$fieldvalue_1->js('change' ,new \atk4\ui\JsReload($fieldvalue_2,['val' => $fieldvalue_1->jsInput()->val()]));