Reputation: 11
Is it possible to get all the fields that are in error within a Tapestry form component or is it possible to override the default Tapestry form validationTracker ?
Upvotes: 1
Views: 126
Reputation: 1719
If you want to show the errors next to the respective fields you can achieve that with custom validation
On the java side:
@InjectComponent
private Form myForm;
@InjectComponent
private TextField myTextField;
@Property
private String textFieldValue;
public void onValidateFromMyForm()
{
if (myConditionBasedOnTextFieldValue)
{
myForm.recordError(myTextField, "Error message");
}
}
On the .tml side
<t:Form t:id="myForm">
<t:TextField t:id="myTextField" value="textFieldValue"/>
<t:LinkSubmit>Submit</t:LinkSubmit>
</t:Form>
Once you submit the form the textFieldValue on the java side will be populated with the contents of the textfield before the validate event is called. The form will not succeed given it has recorded errors against it and since we recorded them against myTextField the error will render next to the textfield itself, instead of being grouped into a lump on <t:Errors/>
Hopes this guides you in the right direction
Upvotes: 0
Reputation: 11
what do you mean with "get all fields"?
if you want to display all fields, they have a validation error so insert into to your form the "Errors" component like this:
<t:form>
<t:errors/>
<t:label for="search"/>
<t:textfield t:id="search"/>
<input type="submit" value="Search"/>
</t:form>
</body>
have a look at api docs
Upvotes: 1