Joomla 支持 XML 表单。所以我实现了其中一个,我还在其中使用了一个子表单。我需要以编程方式更改子表单中的属性。怎么做。
genprice.xml
<?xml version="1.0" encoding="utf-8" ?>
<form>
<fieldset name="basic">
<field name="categories" type="jscategory" required="required" multiple="multiple" />
<field name="attr_polirovka" type="jsextrafield" required="required" default="2"/>
<field name="prices_material" type="subform" multiple="true"
layout="joomla.form.field.subform.repeatable-table" buttons="add,remove"
formsource="administrator/components/com_genprice/models/forms/price.xml" />
<field name="discount" type="text" required="required" default="30" />
</fieldset>
</form>
价格.xml
<?xml version="1.0" encoding="utf-8" ?>
<form>
<field name="polirovka" type="jsattroption" jsattribute="2" required="required" />
<field name="price" type="text" required="required" default="300000" />
</form>
genprice.php
public function getForm($data = array(), $loadData = true)
{
$form = $this->loadForm(
'com_getprice.genprice',
'genprice',
array(
'control' => 'jform',
'load_data' => $loadData
)
);
$input = $prices->setFieldAttribute('prices_material.price', 'jsattroption', '1');
if (empty($form))
return false;
return $form;
}
我尝试更改属性的值:
$input = $prices->setFieldAttribute('prices_material.price', 'jsattroption', '1');
告诉我怎么做?
通过setFieldAttribute我们只能更改price_material字段本身的属性。setFieldAttribute 方法调用 findGroup 方法(指定了字段组)和具有 xpath 查询的 findField ('descendant::field[@name="' . $name . '" 和 not(ancestor::field/form/* )]' ) - 第二部分不包括获取必填字段,因为该字段将包含字段/表单祖先(指定一组字段时,有类似的请求)。
问题本身的解决方案: