views:

209

answers:

1

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]

A simplified version of the source .tml is below.

<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?

+2  A: 

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.

In your TML:

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

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

$('theClientIdOfMyFormInjector').trigger();

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

The component class:

@Inject
private Block formFieldsBlock;

@OnEvent(component = "injector")
Block loadExtraFormFields() {
    return this.formFieldsBlock;
}
Henning
This did the trick, thank you very much!
ponzao
Do you happen to know how I can change context information on the fly? I am currently passing the back-end an id with t:context="item.id", but I am having trouble finding where I can dynamically change this.
ponzao
@Ponzao: Sorry... change where to do what? (Maybe this would make a good new question?)
Henning
Yeah I'll make a new question, just a moment.
ponzao
I added a new question http://stackoverflow.com/questions/2974282/modifying-context-information-in-tapestry-5-dynamically.
ponzao