-
-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OBPIH-4895 add validation on create product type with empty code and product identifier #3533
OBPIH-4895 add validation on create product type with empty code and product identifier #3533
Conversation
if (productTypeInstance.save(flush: true)) { | ||
if (!params.code && !params.productIdentifierFormat) { | ||
productTypeInstance.errors.rejectValue("productIdentifierFormat","productType.codeOrIdentifierRequired.message") | ||
productTypeInstance.errors.rejectValue("code", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is that line responsible for? the one with "code"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was that when neither of two fields have values it should display a validation error at the top with a message: productType.codeOrIdentifierRequired.message
and should highlight both fields (red border) where the error is coming from.
To do that we need to assign errors to those fields with rejectValue(fielName, message)
.
Since error is triggered when both fields are null
I needed to display one message so I assigned that message to one of two field errors and other one set to empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad, I thought there was ||
, not &&
.
Anyway, wouldn't it work if you left only first line? In the line below you write !productTypeInstance.hasErrors()
, so even if you had only
productTypeInstance.errors.rejectValue("productIdentifierFormat","productType.codeOrIdentifierRequired.message")
it would trigger the error (because at least one error exists), wouldn't it? Or do I misunderstand something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but I also wanted to mark the fields that the error is associated with.
On create.gsp
there is checking for field errors on each field
<tr class="prop">
<td valign="top" class="name">
<label for="code"><warehouse:message code="productType.code.label" default="Code" /></label>
</td>
<td valign="top" class="value ${hasErrors(bean: productTypeInstance, field: 'code', 'errors')}">
<g:textField class="text" size="80" name="code" value="${productTypeInstance?.code}" />
</td>
</tr>
if field has errors, it applies class errors
with red border styling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, now sounds reasonable :)
No description provided.