dojo - Spring form field errors with Dijit Controls -
i have simple form using spring form controls. using dojotype on controls.
ex: <form:input path="salary" style="width:10em" dojotype="dijit.form.validationtextbox"/>
i doing form validation dojo. added server side validation spring. trying use springs validation update dijit fields highlighted errors. came with. feels hack , wondering if has better solutions.
first on bottom of form have hidden span element lists errors returned spring:hasbinderrors so:
<span id="allerrors" style="visibility:hidden"> <spring:hasbinderrors name="myform"> <c:foreach var="error" items="${errors.allerrors}"> ${error.field} </c:foreach> </spring:hasbinderrors> </span>
then have dojo function added onaddload spilts string of form fields, removes brackets, , sets dijit class error field this:
dojo.addonload(displayerrors); function displayerrors() { dojo.foreach(dojo.trim(dojo.byid("allerrors").innerhtml).split(" "), function(value) { var newval = value.replace(/[\[\]]/g, ''); if (dojo.byid(newval+'.errors') != 'undefined') { dijit.byid(newval).state = "error"; dijit.byid(newval)._setstateclass(); } }); }
(the reason doing replace because spring generates id attributes without brackets leaves them on name attribute. errors referenced name not id.)
this works fine wondering if else came across solutions similiar or if there easier way of doing same thing.
thanks
Comments
Post a Comment