【问题标题】:Agile toolkit atk4 php set field value based on anther field value without submitting the form敏捷工具包atk4 php根据另一个字段值设置字段值而不提交表单
【发布时间】:2021-10-27 15:56:22
【问题描述】:
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' => true ,'readonly' => false, ['dropdownOptions' => ['fullTextSearch' => true]]]);

$form->addField('field2', ['caption' => 'Select Specfic Values', 'DropDown','model' => new view_values($db),'dependency' => function (view_values $模型,$数据) {isset($data['field1']) ? $model->addCondition($model->fieldName()->id, 'like', '%' . $data['field1'] . '%') : null;} ,'isMultiple' => true ,'readonly' => false, ['dropdownOptions' => ['fullTextSearch' => true]]]);

问题是致命错误 atk4\ui\Exception: Unable to add form field (), object: atk4\ui\FormField\DropDown () property: "dependency" value: {}。寻求帮助。也许我的逻辑是错误的。

【问题讨论】:

  • 花点时间阅读帮助中心的editing help。 Stack Overflow 上的格式化与其他站点上的不同。您的帖子看起来越好,其他人就越容易阅读和理解它。
  • 请澄清您的具体问题或提供更多详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。
  • 嗨,谢谢大家的回复,我正在使用敏捷工具包开发应用程序,如果有意义的话,我正在寻找级联两个下拉字段值的工作示例,任何关于如何完成的想法!
  • 我在这里使用了示例 ui.agiletoolkit.org/demos/form-control/lookup-dep.php ,但我遇到了与 ('dependency' => ) 不同的问题,因为表单不想构建 addfield !所以我正在寻找一个更好更简单的例子,我可以有 2 个字段下拉列表,一旦第一个字段选择第二个字段,就从模型中显示选定的值!

标签: php field agile atk4 agiletoolkit


【解决方案1】:
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()])); 

【讨论】:

  • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
猜你喜欢
  • 2021-10-21
  • 1970-01-01
  • 1970-01-01
  • 2021-06-22
  • 2014-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-05
相关资源
最近更新 更多