1

I would like to style my forms in case of errors a bit more. Standard-usage is to print the error with help of <f:errors path="name" cssClass="error" />

But I want to mark the corresponding text fields as well - maybe by adding an additional style.

Can this be done in an easy way?

Thanks in advance and cheers

Martin

3 Answers 3

5

So late, but it can be useful for someone else.
A very easy way now, using the cssErrorClass, i.e.:
<form:input path="id" class="form-control height30px" cssErrorClass="form-control height30px error"/>

Sign up to request clarification or add additional context in comments.

Comments

3

One easy way I can think of is:

<c:set var="inputCls" value="niceInputCls" scope="page" />

<form:errors path="name" cssClass="error">
<c:set var="inputCls" value="errorInputCls" scope="page" />
</form:errors>

And in your input tag:

<form:input path="name" cssClass="${inputCls}" />

You can define your normal input and error input style classes.

1 Comment

Thanks for your answer. So if I have a page with lets say 20 form fields, I have to add his to every form field? Is there a more generic and simpler way?
0

You can do that as well for the input fields here is that example :

http://www.mkyong.com/spring-mvc/spring-mvc-form-errors-tag-example/

1 Comment

Thanks for your answer, but this is actually not the solution I wanted. I want to add a custom style to the <input> field itself; for example to give it a red border.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.