【发布时间】:2013-08-15 04:49:30
【问题描述】:
我已经开始在 Grails 中设计和实现一个博客主页,以练习 Grails 开发和 HTML。我对 HTML4/5 还不是很熟悉。
我的问题是我想禁用 HTML5 的表单验证,标准消息是:“请填写此字段”,如果该字段是必填字段但未填写,而是使用我自己的自定义错误文本,可以输入文件 i18n/messages.properties。
我已经阅读了这两个关于如何使用novalidate="" 或autocomplete="off" 在纯 HTML5 中禁用表单验证的问题
我已经在我的 Grails 项目中生成了脚手架模板,方法是输入:install-templates。
我的计划是更改 _form.gsp 以在方法 renderFieldForProperty() 中包含 autocomplete="off" 或 novalidate="",但两者都不起作用。
希望有人解决了这个问题并希望分享知识;)
编辑:来自脚手架的 renderFieldForProperty() 代码:
private renderFieldForProperty(p, owningClass, prefix = "") {
boolean hasHibernate = pluginManager?.hasGrailsPlugin('hibernate')
boolean display = true
boolean required = false
if (hasHibernate) {
cp = owningClass.constrainedProperties[p.name]
display = (cp ? cp.display : true)
required = (cp ? !(cp.propertyType in [boolean, Boolean]) && !cp.nullable && (cp.propertyType != String || !cp.blank) : false)
}
if (display) { %>
<div class="fieldcontain \${hasErrors(bean: ${propertyName}, field: '${prefix}${p.name}', 'error')} ${required ? 'required' : ''}"> <-- At the end of this line i have tried the to attributes mentioned above
<label for="${prefix}${p.name}">
<g:message code="${domainClass.propertyName}.${prefix}${p.name}.label" default="${p.naturalName}" />
<% if (required) { %><span class="required-indicator">*</span><% } %>
</label>
${renderEditor(p)}
</div>
<% } } %>
如果你向右滚动,我已经写了我尝试过我在帖子中提到的 2 个属性的地方。
【问题讨论】:
-
请出示您的
renderFieldForProperty()代码或您尝试过但没有奏效的任何其他代码。
标签: html forms validation grails