-
Notifications
You must be signed in to change notification settings - Fork 115
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
FIX Retain value that failed validation on client side #930
FIX Retain value that failed validation on client side #930
Conversation
9da12b8
to
b543861
Compare
a99f5bb
to
6d8e29f
Compare
2da5c6f
to
65e2d6c
Compare
@emteknetnz A few UX type things which you might be able to fix as part of this issue but might be better placed as separate issues.
A good UX experience would be highlighting blocks with some sort of visual indication which have error. |
Unfortunately not possible without very hacky code, because it would be jquery updating a rendered react component |
If there wasn't another competing error at the top of the page which is kinda repeating information, and also close in proximity perhaps. Watching the video it's very in your face when you have multiple errors showing with multiple error notifications as well, and then there are instances where the field shows an error too. Just think this might be doing more harm than good having so many errors present. I understand there might be technical limitations which mean the experience is sub-optimal especially with #4 not being possible. I think we absolutely need an error to be sticky near the top incase people might miss the fading toast notifications. An idea (might not be the right thing?), we might have the possibility to use sticky toasts with a dismiss (x). Then the top alert info could be transferred into the toast. I don't think we've used the Toast dismiss yet but this could be an okay scenario to use it.
This was actually seen as best practice years ago when lots of errors can present (pretty sure it still would be), means you can assess all the issues in one place to get a sense of what needs to be done. Helps to prevent people correcting one field and then try to save the form again but only to get the following issue for each repeated save. Keen to hear your thoughts on moving the top alert info to a sticky toast @emteknetnz |
65e2d6c
to
fc19dc9
Compare
yarn.lock
Outdated
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.
Not sure why these changes are here but given this is an automatically generated file I'm inclined to keep them
11d1d4f
to
e01463a
Compare
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.
Changes to this file are to make the tests more robust, mirroring the equivalent assertions in the new validation failed feature tests.
} elseif ($negate) { | ||
$this->assertFieldNotContains($field, $content); | ||
return; | ||
} | ||
|
||
$actual = (string) $fieldElem->getValue(); | ||
$regex = '/^' . preg_quote($content, '/') . '$/ui'; | ||
|
||
if ($negate) { | ||
$message = sprintf('The field "%s" value is "%s", but "%s" expected.', $field, $actual, $content); | ||
Assert::isTrue((bool) preg_match($regex, $actual), $message); | ||
} else { | ||
$this->assertFieldContains($field, $content); | ||
$message = sprintf('The field "%s" value is "%s", but it should not be.', $field, $actual); | ||
Assert::isFalse((bool) preg_match($regex, $actual), $message); | ||
} |
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.
assertFieldNotContains()
and assertFieldContains()
failed because the $field
variable wasn't a string (so obviously this part of the code just never worked but was never used).
The new assertions mirror what assertFieldNotContains()
and assertFieldContains()
methods would have done. I don't use those directly because those will look fo the fields on the page, not on the block - and since we already have a reference to the field on the block, it's more sensible to just check against that directly here.
} else { | ||
// No validation result returned | ||
// assume everything is valid and reset stores so data is refetched. | ||
resetStores(); | ||
} |
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.
This is needed for compatibility with versions of silverstripe/admin that don't have the accompanying PR.
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.
I think I'd prefer to just tighten the constraint within elementals composer.json to ^1.13.2
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.
Done. CI will break until admin is tagged.
// Reset the store if the user navigates to a different part of the CMS | ||
// or after submission if there are no validation errors | ||
if (!$('.cms-edit-form').data('hasValidationErrors')) { | ||
resetStores(); | ||
} |
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 condition doesn't explicitly test for anything to see if it's swapping to a new page - but it doesn't need to. This condition evaluates to true
when navigating to a new page. I've confirmed this under the following scenarios:
- No form submission has happened yet. I click to a different page.
- A form submission happened and there were no validation errors. I click to a different page.
- A form submission happened and there were validation errors. I click to a different page.
e01463a
to
7b3e94c
Compare
7b3e94c
to
c473c1e
Compare
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.
I clicked "Comment" rather than "Request changes" because I'm unable to request changes since I'm the original author on this PR
} else { | ||
// No validation result returned | ||
// assume everything is valid and reset stores so data is refetched. | ||
resetStores(); | ||
} |
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.
I think I'd prefer to just tighten the constraint within elementals composer.json to ^1.13.2
Getting validation errors to display nicely on blocks is out of scope - we're just making it so if there _are_ validation errors, block content is not lost.
c473c1e
to
2c32dc8
Compare
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.
APPROVE
(I cannot tick approve because I'm the original author on the PR)
Tested locally, it's certainly a big approvement though the UX still isn't quite there
When I make inline edits to a content block such as changing the title and then save the page and fail page validation, the content block edits are retained, though the when the page edit form is refreshed the content block title appears unchanged in a closed state. When you open the content block to inline edit it the changes are now applied.
That said, it is now retaining the edits which is a great improvement
Requires this PR silverstripe/silverstripe-admin#1246 to get the ValidationResult client-side
Videohttps://www.youtube.com/watch?v=NvWJHFSHijocustom "required" validator on content block titleRequiredFields validator on a custom page fieldPage has multiple tabs that show invalid iconsMake sure you squash commits on merge
There are two commits so it is clear what was done originally vs what has been done more recently. The original commit may be useful for historical purposes but when merging, this PR should be merged with squashed commits.
CI
The CI won't go green until silverstripe/silverstripe-admin#1246 is merged in, so I've run an installer CI run: https://github.com/creative-commoners/silverstripe-installer/actions/runs/4985675862
Note that the failed unit test in the installer CI run is unrelated to this work.
Issue
#764