【发布时间】:2016-09-21 07:29:23
【问题描述】:
我的域对象预订有多个允许为空的属性,因为它们将在对象保存到数据库后稍后设置。
myService.action() 的一部分:
booking.properties = params
if (booking.contactFirstname?.length() <= 1) { booking.errors.rejectValue("contactFirstname", "empty") }
if (booking.contactLastname?.length() <= 1) { booking.errors.rejectValue("contactLastname", "empty") }
if (booking.contactPhone?.length() <= 1) { booking.errors.rejectValue("contactPhone", "empty") }
if (booking.contactMobile?.length() <= 1) { booking.errors.rejectValue("contactMobile", "empty") }
if (booking.contactEmail?.length() <= 1) { booking.errors.rejectValue("contactEmail", "empty") }
if (booking.hasErrors() || ! booking.validate()) {
return [success: false, model: booking]
} else {
booking.save(failOnError: true)
return [success: true, model: booking]
}
我的控制器会:
def result = myService.action(params)
if (result.success) {
flash.success = message(code: "msg.successfullySaved")
redirect(action: "registerEventConfirmation", id: result.model.uid, params: [lang: params.lang], mapping: "paginated")
} else {
flash.error = message(code: "msg.errorSavingCheckFields")
render(view: "registerEventStep3", params: [lang: params.lang], model: [booking: result.model])
我正在使用 hasErrors(bean: booking,field:'contactFirstname', 'has-error')}
标记错误字段。
如果我现在提交的表单在文本字段中没有任何值,所有字段都是红色的,booking.errors 有 >0 个错误。
如果我在使用名字之后提交表单,则 booking.errors 为 NULL,并且没有标记其他字段。
这是一个错误吗?我使用 Grails 2.3.6
其他信息
- 我访问了表单,提交时完全是空的
- 我看到所有表单字段都是红色的,object.errors 有 >0 个错误 (VALID)
- 我在第一个字段中输入一个值,名字并提交
- 我没有看到任何红色的表单域,object.errors =0 错误(无效)
- 我重新提交表单,没有任何更改
- 我看到所有空的表单字段都是红色的,object.errors 有 >0 个错误 (VALID)
【问题讨论】:
标签: grails