Announcement Announcement Module
Collapse
No announcement yet.
No client-side validation for String fields with max > 30 chars Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • No client-side validation for String fields with max > 30 chars

    An entity with this field (or any length of 30 or less):

    Code:
    @NotNull
    @Size(max = 30)
    private String name;
    Will have this text field in its create/update view:

    Code:
    <form:input cssStyle="width:250px" id="_name_id" maxlength="30" path="name" size="0"/>
    <br/>
    <form:errors cssClass="errors" id="_name_error_id" path="name"/>
    <spring:message arguments="Name" code="field.invalid" var="field_invalid"/>
    <spring:message code="field.required" var="field_required"/>
    <spring:message argumentSeparator="," arguments="Name,(${field_required})" code="field.simple.validation" var="field_validation"/>
    <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : '_name_id', widgetType : 'dijit.form.ValidationTextBox', widgetAttrs : {promptMessage: '${field_validation}', invalidMessage: '${field_invalid}', required : true}})); </script>
    Whereas if the field's max is over 30, you get a text area instead:

    Code:
    <form:textarea cssStyle="width:250px" id="_name_id" path="name"/>
    <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : '_name_id', widgetType: 'dijit.form.SimpleTextarea', widgetAttrs: {}})); </script>
    <br/>
    <form:errors cssClass="errors" id="_name_error_id" path="name"/>
    The difference to the user is that in the second case, there's no client-side validation, i.e. the field doesn't get the nice decorators when it loses focus and is still empty.

    Can anything be done about this lack of validation, preferably by enhancing Roo or even via a manual change to the view?
    Last edited by Andrew Swan; Jan 28th, 2010, 10:54 PM. Reason: Forgot the first set of CODE tags, oops

  • #2
    We are aware of this issue and it is documented in ROO-440. The problem is that Dojo's Textarea does not recognize the required flag and it is also not possible to decorate it with a validator. So there is currently not too much we can do. We hope to change this soon.

    Comment


    • #3
      Try Forms4j (www.forms4j.com) -- it will handle your error messages, maxlength and mandatory conditions for both client and server side.

      Code:
      <forms4j:input id="foo" maxlength="30" mandatory="true" />

      Comment

      Working...
      X