Reputation: 59
My issue is that I would like to retrieve a textfield value without submit my form.
I think the solution should be a mixin event but I am not good enough to perform this.
Here an example about what I try to do :
<form t:type="form" t:id="myForm">
<t:errors banner="msgError" />
<t:zone t:id="zone1" id="zone1" elementName="zone1">
... some fields ...
</t:zone>
<t:zone t:id="zone2" id="zone2" elementName="zone2">
<t:label for="select">Société :</t:label>
<t:select t:id="select" model="selectModel" encoder="myEncoder"
value="selectedvalue" blankOption="never" />
<t:if test="isAdd">
<input t:type="TextField" t:id="valueField" t:validate="required"
size="45" t:value="value" />
<t:actionlink t:id="addNew" context="value">${message:add }</t:actionlink>
<p:else>
<t:actionlink t:id="add">${message:add } ?</t:actionlink>
</p:else>
</t:if>
</t:zone>
<t:zone t:id="zone2" id="zone2" elementName="zone2">
...some other fields;
</t:zone>
<input type="submit" value="${message:valid }" />
So, I would like a button or link for add dynamically an option for my select. The select is feeded by my DAO. The goal is to get a link that change the statut of "isAdd" and then, display a textField with a button for adding a new value in my database and refresh the select component. I am sorry for my english, I hope you can understand the meaning...
Note that I have no constraint and can use javascript/ajax.
The answer can help me in many usages so I would be really happy if you can.
Tell me if you need more informations, thanks.
Upvotes: 1
Views: 2977
Reputation: 27994
You could use the observe mixin from tapestry-stitch. Attach the mixin to the 'click' event on the button button and set the fields
parameter to the clientId of the textfield. Note, you'll probably use the Any component to render your button. Since, I'm guessing, you don't need the textfield value in the submit of the form, you could use a normal html input instead of a TextField.
TML
<t:zone t:id="myZone">
<t:select ... />
</t:zone>
...
<input type="text" id="valueField" />
<t:any
t:id="addNew"
element="button"
t:mixins="stitch/observe"
event="click"
zone="myZone"
fields="['valueField']"
>${message:add}</t:any>
Java
@Inject
private Zone myZone;
Object onClickFromAddNew(String value) {
// do stuff
return myZone.getBody();
}
Upvotes: 2