Add constraints to the elemets of List

MaxR

New member
Is there are any possible way to add constraints to the elements of List? For example I have a command which accept List and I want add constraints on this elements, for example on size.

Code:
class SongCommand {

    String title
    List<String> couplet
    List<String> chorus
    Boolean isChorus
    Boolean isChorusRepeat

    static constraints = {
        title(blank: false, maxSize: 6)
        isChorus(blank: true)
    }

}

How to do that?

Thank you.
 

MaxR

New member
I have the solution
Code:
static constraints = {
  couplet(validator: { val ->
    boolean isValid = true 
    val.each {
      if (it.size() < 3) isValid = false
    } 

    return isValid
  })
}

It's not final, but as example. Better return error code message, not true/false.
 
Top