Announcement Announcement Module
Collapse
No announcement yet.
What's the best way to make input fields optional? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • What's the best way to make input fields optional?

    Hello,

    by default, Roo make all input fields in create/modify/find forms mandatory.

    A client of mine has asked me to make some fields optional in the form which lets users input customer details. As a result, I have added a <c:if ...> statement in input.tagx which makes input fields optional via Javascript whenever the sec_field variable is equal to the name of the fields which should be optional (eg, firstName, address1, address2, but not lastName, and email).

    This method has two shortcomings:

    - null values are inserted into the database and are displayed whenever users create other entities associated with customers (eg, cars where each car is associated with one customer; the customer popup menu in the Car Form will show nulls where the customer values were optional)
    - there is no way distinguish between two member fields with the same name (eg, Client.email and Supplier.email) in input.tagx. As a result, both fields become optional.

    Is there a better way to make fields optional in Roo than adding <c:if> tags to input.tagx which modify the field-content-checking Javascript?

    Many thanks.

    Philroc

  • #2
    Fields are only mandatory if you annotate them with @NotNull or equivalent. This leads to a required="true" attribute in the field:input tag.

    Comment

    Working...
    X