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

Attach the xhr violation error to the form field #7948

Merged
merged 2 commits into from
Oct 20, 2022

Conversation

ggabrovski
Copy link
Contributor

@ggabrovski ggabrovski commented Oct 14, 2022

Attach the xhr violation error to the form field

In relation to @dmitryuk fix for #7945 #7946 it will be nice for the user to see the violation error message attached to the field. I suggest to add small logic to display this information on the right place.

Changelog

### Fixed
- Violations error handling

@VincentLanglet
Copy link
Member

Can you provide a screenshot of what you get ?

@ggabrovski
Copy link
Contributor Author

In the moment if you have ModelAutocompleteType with add button. When you try to add new record validations error are not show. @dmitryuk fix #7946 will show the validation error on top.
Like this:

befor

I suggest to attach the violation error to the related form field:

after

VincentLanglet
VincentLanglet previously approved these changes Oct 15, 2022
@dmitryuk
Copy link
Contributor

Guys please merge PR and add a tag

@VincentLanglet
Copy link
Member

I'd like the review of @jordisala1991 first

const field = $(form).find(`[name='${violation.propertyPath}']`);
if (field.length) {
field.closest('.form-group').addClass('has-error xhr-violation-error');
field.parent().append(`<div class="help-block sonata-ba-field-error-messages xhr-violation-error-block">
Copy link
Member

Choose a reason for hiding this comment

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

This won't work if one field triggers 2 validation errors. IMO this code should be written in plain JS, and you can use some (or all) the logic written here: https://github.com/sonata-project/SonataPageBundle/blob/4.x/assets/js/composer.js#L255-L300

It should be quite similar.

@ggabrovski
Copy link
Contributor Author

Hi @jordisala1991,
thanks for your help and guidance. Can I ask you to check it, please.

@dmitryuk
Copy link
Contributor

@jordisala1991 please check the pr

Copy link
Member

@jordisala1991 jordisala1991 left a comment

Choose a reason for hiding this comment

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

IMO it looks good now, but we also need to move symfony/serializer from require-dev to require. It is a hard dependency

@jordisala1991 jordisala1991 merged commit d7a691b into sonata-project:4.x Oct 20, 2022
@jordisala1991
Copy link
Member

Thank you @ggabrovski

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants