-
Notifications
You must be signed in to change notification settings - Fork 116
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 Improve non-inline validation #1178
FIX Improve non-inline validation #1178
Conversation
f78190a
to
49c532b
Compare
49c532b
to
4045901
Compare
* This will perform FormField validation | ||
* DataObject validation will happen in saveInto() as part of $element->write() | ||
*/ | ||
public function validate($validator) |
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.
Previously FormField validation wasn't happening on fields on elements e.g. $db = [ 'MyUrl' => UrlField::class ]
when saving the page (as opposed to editing the element directly)
bc3ff5a
to
31201ec
Compare
4488a86
to
e1674f8
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.
If I save the page without expanding the block, none of the validation seems to happen. e.g. with your test blocks from the description, I add the block and immediately save the page - it should trigger validation errors for the missing required fields but it doesn't.
3c23c58
to
f1ad55d
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.
The problem described in #1178 (review) has not been resolved
That would be hard to solve. In the case of inline blocks, currently if they haven't been opened and the page is saved, then then because the child FormBuilder form hasn't been rendered then the element data will not be sent as part of the page form submission. However if the inline-element is opened then page save will submit element data with the rest of the page, and closing the element then saving the page will also send the element data. So to solve this we'd need to render the FormBuilder forms for ALL unopened elements on page save In the case of non-inline blocks, I really don't know what can be done since their forms are never rendered on the page and and thus their data is never sent. The fact this doesn't work doesn't actually matter given the AC is We could split this off as a seperate card, though I honestly don't know how or even if we should attempt a fix here |
I think that's worth looking into. There's a tradeoff to be made between:
I'll open a separate card about this for discussion. Edit: #1183 |
f1ad55d
to
9539290
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.
Just the one thing left and then we're good, I think.
Reran CI after merging frameworktest. Confirmed they are running with the correct commit: |
behat failing |
8516a9e
to
eba37f1
Compare
I've added an extra code change that's from a different PR that's blocked on this one which is required to get the inline-block-validation.feature behat tests to pass |
@@ -139,7 +139,7 @@ public function save(array $data, Form $form): HTTPResponse | |||
$dataWithoutNamespaces = static::removeNamespacesFromFields($data, $element->ID); | |||
|
|||
// Update and write the data object which will trigger model validation | |||
$element->update($dataWithoutNamespaces); | |||
$element->updateFromFormData($dataWithoutNamespaces); |
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've added this code change in from a different PR that's blocked on this one which is required to get the inline-block-validation.feature behat tests to pass
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 don't know how I didn't notice this before, but for inline-editable blocks when you save the page, only one required field validation message appears at a time.
So if I don't enter any data I only get told about the title, then I add a title and I'm told about the image, then I add an image and I'm told about the page.
The HTTP response does have all three validation errors at the same time - at this stage I don't know if getting them to display is part of this card or not so if there's another card to handle this please just link to it and I'll be okay with that.
Rerunning failed behat tests now that the framework PR is merged, but regardless of whether that goes green I need at least a response to my above comment. |
eba37f1
to
e2f742b
Compare
Still need to respond to #1178 (review) |
Split of as separate card that can be refined |
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.
LGTM with the understanding that there's still a few issues left to be done before this functionality is considered 100% working 😅
…non-inline-validation FIX Improve non-inline validation
…non-inline-validation FIX Improve non-inline validation
Issue #1155
Need to merge silverstripe/silverstripe-framework#11213 first to get the has_one RequiredFields validation working correctly and silverstripe/silverstripe-frameworktest#172 to get behat to pass.
There is a mutli-pr CI run linked on the issue
Note that this PR does not touch inline-saving
Scenarios:
Non-inline editable block:
Inline-editable block page save
I used the following blocks to tests these scenarios