-
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 Come up with an approach to validate inline blocks #1068
Comments
tl;dr - IMO there is only one "correct" way to handle inline validation which is to utilise the existing FormSchema.php + FormBuilder.js functionality to do everything in relation to inline XHR saves and validation. IMO there aren't any good viable alternatives to doing this, so I haven't provide any What's happening right now is we use the existing functionality for rendering the inline form, but not for validating/saving the data in it. I've got a draft PR that is the net result of my investigation. This was very slow and painful trying to work out what's currently happening at trying to move it toward the state it should have always been in. As usual everything is hard with incomplete implementations, things are undocumented and there's lots of jumping around the place. Going forward I think we should simply continue with the draft PR and work on that until it's all wired together. This may require some work in silverstripe/admin FormBuilder.js as well. We could also consider if we want a more centralised FormSchema API controller, though the work here could and possibly should happen independently of that for now and we just migrate to that later. The following is a bit of a dump of various things: GETing elemental data:
POSTing elemental data
Frontend validation as you type
|
I think that's a bit overkill - we don't provide that anywhere else in the CMS. For now lets just focus on getting validation working at all, and then we can look at our validation across the board and decide if and where and how we want to apply validation as you type. |
@emteknetnz There's currently two ways to save inline elemental forms - through the save button on the block itself, and by saving the whole page. |
Only the inline save, I've paid no attention to the page save. I'm kind of making an assumption that later on we'd want to drop the page save method altogether, and only save inline blocks via their own XHR requests that would be triggered when clicking the page save button. I'd like to not have 2 ways to do the same thing, it adds a massive amount of overhead effort to maintain, just ends up wasting time.
FormBuilder.js supports this right now and we should be making use of it if possible IMO. It will block submitting the redux-form which is really nice. |
There's probably very little to peer review here, which makes sense since it's a SPIKE The conclusion I came to was basically "There is this existing FormSchema + FormBuilder functionality that we should be using because it supports validation, so let's use it" |
Fair enough. I'd say we want the validation experience to be the same regardless of which button people are clicking to save their data, so we should do both at once IMO. Specifically:
That sounds great, and IMO we should do that right away if that more easily lends itself to validating in a consistent way. At the end of the day the content authors don't care whether it's a separate XHR request triggered when clicking the save button, or if the data is all shoved through together with the page data. They just care that when they click the button, they have validation errors if there are validation errors and stuff is saved otherwise.
I'm not saying "lets never do that" - I just think that there's two concerns here. One is getting validation working at a base level, consistent with the rest of the CMS. We can then look at as-you-type validation as a separate concern IMO and try to get that implemented in a consistent way across the board for a clear and consistent validation experience. It would be a weird CMS Author experience if sometimes stuff gets validated as you type, but sometimes it doesn't. Authors shouldn't have to care that this comes from this module so it does things this way, and that comes from that module so it does things that way.
That sounds sensible to me. |
Yeah if we want a consistent UX experience I think it's borderline a requirement to get rid of the "save element content in the same request as saving the page content" functionality, which is actually pretty similar to what linkfield does now.
I suspect this is going to be significantly easier to get going on linkfield first because it's simpler and we've already agreed to a new major version making it easier to change things, so I'd be inclined to see how that goes first before tackling this one. We'd be able to have a more informed discussion if we've already got that under our belt. |
just want to throw my 2c in here re the saving mechanic. I'm all for a single way to do things but there's a common pattern I've seen on projects to disable the publish on individual blocks and instead have only a page level publish. This is because content authors usually do not want a partial update to the page (or at least its an easier mental model). If we're saving blocks individually it would be good to make sure it is compatible with preventing a page publish (or save for that matter) when a validation error occurs. On the face of it this appears to require some 'waiting' for blocks to save before allowing a page save. |
This would only be for saving blocks, not for publishing blocks In my head, on page save click all the elements would, if in a changed state, fire off their own XHR's to validate/save and the page save button would wait for all of those to resolve first. If there's any validation errors then there this would prevent the page form from submitting and all of the relevant blocks with validation errors would pop open and show the validation errors on the relevant fields. Ditto clicking the page publish button, though again it would inline save blocks, not inline publish blocks. For actually publishing the blocks there's no need to XHR everything because we just rely on ElementalPageExtension.$owns = ['ElementalArea'] and ElementalArea.$owns = ['Elements'] to cascade publish the blocks when the page is published |
That was a massive pain in the but to getting AnyField working with Elemental block. That definitely give some pretty hackish vibe.
That sounds fine to me. I guess there's a wider question about whether we want form schema to support JSON data submission or facilitate it. But that doesn't need to be answered here.
Campaign admin seems to have figured out the "Validation" part of form schema. I don't know if it's a proper fix or a hack thought.
I wouldn't block the card on it. But I think it's something worth investigating as part of our wider form schema work. I'm thinking it might actually be easier to validate the elemental block form as you go rather than the parent form + multiple elemental block all at once. Saving/Publishing individually or via the pageI would be very concerned if we forced content author to save their block individually without giving them the option to save them all at once through the parent page. I would want us to sit down with a bunch of content authors before making such a big change to their workflow. Would triggering the individual "block save" when saving the page, before triggering the main page save be an option here? Disabling individual block publish does sound like something quite sensible however. |
We think we've got enough info to proceed. We're currently doing similar work on LinkField. We'll draw some lesson from that and apply them to elemental validation. |
We have a gnarly card to implement validation for inline blocks.
TODO
Timebox
2 days (with potential for extension if need be)
Parent card
#329
PRs
The text was updated successfully, but these errors were encountered: