I've started to design and implement a blog-homepage in Grails to get practice with Grails development and HTML. I'm not that experienced with HTML4/5 yet.
My problem is that i want to disable HTML5's form validation which standard message is:"Please fill in this field" if the field is required and not filled, and instead use my own custom error-text that can be typed into the file i18n/messages.properties.
I have read these two question on how to disable form validation in plain HTML5 with either novalidate=""
or autocomplete="off"
I have generated the scaffolded templates in my Grails project, by typing: install-templates
.
My plan was to change the _form.gsp
to include either autocomplete="off"
or novalidate=""
in the method renderFieldForProperty(), but neither are working.
Hope somebody have solved this problem and want to share knowledge ;)
Edit: Code from scaffolded 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>
<% } } %>
Above if you scroll right i have written where i have tried the 2 attributes i mentioned in my post.