-1

Hi how do I set the command object constraint nullable, blank, and custom for these 2 list, event[] and qty[] from the below html?

<div class="row-1">
    <select name="event[]" class="form-control ">
        <option selected="">abc</option>
        <option selected="">def</option>
    </select>
    <input name="qty[]" >
</div>
<div class="row-2">
    <select name="event[]" class="form-control ">
        <option selected="">ghi</option>
        <option selected="">jkl</option>
    </select>
    <input name="qty[]" >
</div>


class someCommand implements Validateable {

    List eventComponent
    List qty

    static constraints = {
    }
}
Iverson
  • 179
  • 3
  • 11

1 Answers1

0

Hi how do I set the command object constraint nullable, blank, and custom for these 2 list

You could do something like this:

class someCommand implements Validateable {

    List eventComponent
    List qty

    static constraints = {
        eventComponent nullable: false, validator: { theList ->
            // return true if theList is valid
            // return false or a message code if theList is invalid
        }
        qty nullable: false
    }
}

You wouldn't use blank for a List. blank is for validating String properties. If you want to make sure the list has elements in it, you could use minSize: 1.

I hope that helps.

Jeff Scott Brown
  • 26,804
  • 2
  • 30
  • 47
  • I think you are going to have separate issues because of the way your markup is constructed, but the above answers the question about how to set constraints for those properties. – Jeff Scott Brown Dec 10 '19 at 18:06