在挂毯5更新一个表单内的区域挂毯、表单、区域

2023-09-10 13:33:23 作者:吢丕

我有一个表格是一个包含块输入字段,我想结合的父表格更新。不幸的是这似乎并没有工作得那样容易,因为我希望为我迎接下面的错误消息。

I've got a Zone inside a Form, the Zone is updated with a block containing input fields which I would like to bind to the parent Form. Unfortunately this doesn't seem to work quite as easily as I hoped as I am greeted with the following error message.

The Description component must be enclosed by a Form component. [at classpath:...Page.tml, line 100]

源的简化版本 .tml 如下。

<t:form t:id="editForm" t:context="item.id">
    <table>
        <tr>
            <th>Name</th>
            <td><t:textField value="item.name"/></td>
        </tr>
        <t:block t:id="block">
            <tr class="person">
                <th>Description</th>
                <td><t:textField t:id="description" value="item.description"/></td>
            </tr>
         </t:block>
         <t:zone t:id="itemZone" id="itemZone"/>
         <t:actionlink t:id="item" zone="itemZone">Click me!</t:actionlink>
    </table>
</t:form>

有没有办法做到的结合,如果没有什么其他的替代品有哪些?

Is there a way to do the binding and if not what other alternatives are there?

推荐答案

这个答案已经过时,你可以用通常的区功能添加表单元素的从挂毯5.2 。这种方法仍然有效,尽管肯定。

This answer is outdated, you can add form elements using the usual zone functionality from Tapestry 5.2 on. This method still works as well, though.

FormInjector 组件允许您将表单元素添加到一个已经存在的形式。您必须编写一些自定义的JS触发的形式注入,虽然。

The FormInjector component allows you to add form elements to an exising form. You will have to write some custom JS to trigger the form injection, though.

在您的TML:

<div t:type="FormInjector" t:id="injector" position="below" />

您可以触发注入你的JS code是这样的:

You can trigger the injection in your JS code like this:

$('theClientIdOfMyFormInjector').trigger();

您可以通过它的类名找到你的表单内的注射器DIV( myForm.down('div.t-forminjector'))。

You can find the injector DIV inside your form by its class name (myForm.down('div.t-forminjector')).

组件类:

@Inject
private Block formFieldsBlock;

@OnEvent(component = "injector")
Block loadExtraFormFields() {
    return this.formFieldsBlock;
}