Grails min constraint for date validation

爱⌒轻易说出口 提交于 2019-12-01 15:55:25

Try using a custom validator:

static constraints = {
    endDate(validator: { val, obj ->
        val?.after(obj.startDate)
    })
}

val is the value of the field and obj is a reference to the object being validated. The closure can contain whatever logic you need, so you can extend your validation in the way you're describing in your question (by accessing the child objects you refer to using obj).

The custom validator is pretty flexible. Have a look at the documentation. Ideally you'll want to return a custom message; how to do that can also be found in the docs linked above.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!