Are there any ways to bind arbitrary element's css class to model bind state?
<form:form method="post" commandName="authForm" action="authenticate">
<div id="login-error" class="control-group">
<label>Login</label>
<form:input path="name" />
<span class="help-inline"><form:errors path="name" /></span>
</div>
<div class="control-group">
<label>Password</label>
<form:input path="password" />
<span class="help-inline"><form:errors path="password" /></span>
</div>
<input type="submit" />
</form:form>
In this piece of code I need to manage login-error
's class to control-group
when there are no errors and control-group error
when there are (the same idea for second control-group
).
What's the common solution here?
Update
Here's what I need when there's no bind error:
<div class="control-group"> <!-- !!!!!!!!!!!! -->
<label>Login</label>
<form:input path="name" />
<span class="help-inline"><form:errors path="name" /></span>
</div>
Here's what I need when there is a bind error:
<div class="control-group error"> <!-- !!!!!!!!!!!! -->
<label>Login</label>
<form:input path="name" />
<span class="help-inline"><form:errors path="name" /></span>
</div>
Looking for solution.
Here's the solution that just works, but I'm not sure if it's really good idea:
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
...
<form:form method="post" commandName="authForm" action="authenticate">
<spring:bind path="name">
<div class="control-group <%= status.isError() ? "error" : "" %>"
<label>Login</label>
<form:input path="name" />
<form:errors path="name" cssClass="help-inline" />
</div>
</spring:bind>
...
</form:form>
I had the same problem and I solved it using jQuery.
<div class="control-group">
<form:label path="groupCode" cssClass="control-label"><spring:message code="lookUp.groupCode"/></form:label>
<div class="controls">
<form:input path="groupCode"/>
<form:errors path="groupCode">
<form:errors path="groupCode" cssClass="help-inline"/>
<script type="text/javascript">
$("#groupCode").parent().parent().addClass("error");
</script>
</form:errors>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With