-
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
SPIKE: Validation not compatible with adding blocks inline in 4.0 #688
Comments
I've fixed the original bug in #584, and a JavaScript error that happens when you haven't loaded any inline editable element forms yet and try to save the page - cannot convert undefined or null to object. The state of play now (using the example code from #584) is:
|
I guess the ideal situation is that the field itself shows the error rather than it being a toast message, e.g. something like this: This would require some adjustment to the ElementalAreaController to return the errors and identify which fields they apply to, and to the SaveAction to propagate those errors back into the Redux state in a way that the element editor form can detect and update to show them. We could then do away with the toast message when there's an error, leaving the success toast message when it saves successfully. Thoughts @silverstripe/creative-commoners? |
I've tested the same patterns in asset admin:
In Elemental we "namespace" the element field names, so it might be a little tricky to support |
What I've done
What I get
Ways to save content
Things to consider
public function validate()
{
$validator = parent::validate();
if ($this->isInDB() && empty($this->Title)) {
$validator->addFieldError('Title', 'Title is required');
}
return $validator;
}
public function validate()
{
$validator = parent::validate();
if ($this->isInDB() && empty($this->Title)) {
$validator->addError('A non-field specific error occurred during validation');
}
return $validator;
} Is this enough to go on for the spike @brynwhyman? I've pushed my WIP to |
Yeah I can imagine we'll need to have some validation payload to put into redux so the form can know about it when it's mounted. It looks like components like
Yeah hopefully if we write something server-side to generate something to put into redux then we can share this with the page-level saving.
Option 3; we don't bother. We don't attempt to save any blocks that haven't been opened when you do a page level save so the validation shouldn't trigger? If a block has become invalid without a content author editing it then that's just general
Agreed. I guess that there's some way this should work with
Perhaps this is also something that PUX can weigh in on I'm a little worried about validation needing to show on blocks that aren't expanded. I think that means we'll have to loop the blocks and run Great investigation though, this is probably enough to go on. I see that we'll probably need to:
Then we just need to figure out how to get validation responses to the client-side. Here is a crazy idea that I've just hatched after chatting with @unclecheese: Toss validation errors from a page level save into Currently we're stuck in a weird half-way case (again) where we're partially using REST/pjax and GraphQL. It makes sense to return validation responses with mutations, but not so much with queries. We can do some magic though where we can add validation errors to "schema data" on the Hopefully individual block saves aren't so painful here. |
One approach to fixing hidden validation errors is to open any blocks with errors so they can be seen. We could apply an additional style to highlight those blocks (e.g. red border on left) if we want to keep them closed—design would be required) for this. |
I've raised an issue to do the work outlined in this issue: I'll close this now (as done) but we can continue discussion.
Yeah - the only concern about that is performance - when you open a block you have to request the form from the server. Doing that for ~5 blocks would be slow and annoying. |
Overview
Given the investigation required, we'll be spiking the effort and implementation detail required in introducing standard SilverStripe validation with inline-editable blocks.
The following issue gives the best detail: #584
Notes
The text was updated successfully, but these errors were encountered: