Skip to content
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

Conversation

drodzewicz
Copy link
Collaborator

No description provided.

if (productTypeInstance.save(flush: true)) {
if (!params.code && !params.productIdentifierFormat) {
productTypeInstance.errors.rejectValue("productIdentifierFormat","productType.codeOrIdentifierRequired.message")
productTypeInstance.errors.rejectValue("code", "")
Copy link
Collaborator

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"?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, now sounds reasonable :)

@awalkowiak awalkowiak merged commit a012d17 into develop Oct 11, 2022
@awalkowiak awalkowiak deleted the OBPIH-4895-add-validation-on-create-product-type-with-empty-code-and-product-identifier branch October 11, 2022 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants