Search code examples
grailsgrails-validation

Only display first error in gsp


I'm performing inline validation on fields as the user tabs between them. A problem occurs when there is more than one error against a field i.e both errors are shown. I only want to show one error (The first one for arguments sake).

Is there are different tag to deal with this?

<jqvalui:renderError for="title">
    <g:eachError bean="${objInstance}" field="title"><g:message error="${it}" /></g:eachError>
</jqvalui:renderError>

Thanks


Solution

  • So essentially you just have to use the errors themselves instead of using the tags provided for you.

    <g:hasErrors bean="${objInstance}" field="title">
        <g:message error="${objInstance.errors.getFieldErrors("title")[0]}" />
    </g:hasErrors>