Prev, Next and Create buttons on detail GridField forms
chillu opened this issue Β· 26 comments
Overview
It's often cumbersome to move through a list of items by clicking into the detail view, hitting the "back" button, and clicking into the next item. The betterbuttons module solved this for 3.x, and there's a good case for making it a core feature. @sachajudd and @clarkepaul have designed a solution as part of a Save and add new button design.
Acceptance Criteria
- I can add a new record from a record detail form
- If choosing to add a new record or navigate to the previous/next record on a record detail form with unsaved edits, I get a prompt and stay on the same screen until I've saved the record explicitly.
- I can navigate to the previous and next records of a list when viewing a record detail form
- If there is no more previous or next records, the button is disabled
- The new buttons don't compromise more important buttons on small screens
- The functionality works in ModelAdmin and any other GridField
- Sorting and filtering is retained
- Does not double up when betterbuttons is installed (might need a patch to that module?) (UPDATE: BetterButtons already takes priority and overrides all the actions)
- Should work in default configurations, but can be opted out of
- Behat Tests written
- Update documentation
- Excludes choosing the type of record to create (that's a thing in some GridField modules)
- Excludes any "save and close" or "publish and close" logic
Designs
Notes
- Some historical context and discussion in a duplicate card
Pull Requests
Yes, this would be an awesome addition!
Please also consider the case where different classes can be added to a relation. Meaning that the "add new" button should turn into a flyout where you can select the class to create (the gridfield equivalent of this is the GridFieldAddNewMultiClass
component added via gridfieldextensions). The elemental-module makes use of this to add the different block-types to a page.
It doesn't have to be in core, but it should be possible to add this via extensions or similar.
4.1.1 here we gooooo!
@sachajudd commented on the duplicate card:
We should have a warning indicating to the user that they have unsaved changes before they navigate away. We thought the "save/publish and create new" action was better suited in the drop-down area.
I've changed the AC accordingly. So the "plus" button would only create a new record, not also save the existing one.
Excludes any "save and close" or "publish and close" logic
So, I think this means that the extra imputed functionality necessary for maintaining Version
'ed DataObject
's managed in GridField
instances will still reside entirely in the betterbuttons
module, is this correct? That is, the special BetterButton_SaveDraft
and BetterButton_Publish
buttons incorporated by the module right now ("Saved" and "Save & publish") and the associated "stage" level DB persistence abstraction interfacing with the Versioned::
API.
If that's not the case, could someone point me in the direction where this will eventually live long term for SS 4+ and onward (if not in betterbuttons
module or in silverstripe-admin
)?
@patricknelson that's correct. This is only porting the Previous
, Next
and Add
buttons on the edit form.
@patricknelson It's an MVP at this point. We need to satisfy the squeakiest wheel, and that's prev/next and add. That's most of the reason why users are installing betterbuttons. Further down the track, I see this API expanding to support additional prebaked and custom actions, and may even do so in 4.4, as this PR isn't going to make it into 4.3 anyway.
@unclecheese I'll give you $5 if it goes into 4.3. rubs hands
Just wondering when this bit can be released to a stable?
It's already in the latest 4.x stable
It will be released in 4.4. Not yet tagged.
@ScopeyNZ Do we have a rough estimate for 4.4? this button would help a lot with a client's data entry.
4.4 should be within the next couple of months. I think there's a tentative schedule to have an RC on the week beginning 6th of May.
Excellent, looking forward to this addition :)
It may have taken half a decade, but it's finally here! I used the buttons today, and they made me very happy. Thanks for all your work, team! πππ
Where do I leave a comment to say that it doesn't work the way it should? Sometimes the Next button is greyed out on a non-final record, and sometimes the Previous button is inactive on a non-first record. I should add that the affected records are ALMOST NEVER page-initial or page-final in the current page of the query.
I have the same problem. The buttons are often disabled, when they shouldn't be.
Please feel free to raise an issue with the problem. Preferably with some accurate steps to reproduce.
Note that I don't think prev/next takes filtered/ordered GridFields into account - @unclecheese you're working on persisting search parameters in the GridField URL state, do you think this might be overlapping?
My guess is that the issue here is non-deterministic sort. Make sure your dataobject has a default_sort defined, or explicitly sort the datalist youβre passing to the grid.
The fact that it happens unpredictably is a good indication that your result set isnβt predictable itself.
I have set a default_sort on my DataObject. The problem still occurs. It does not occur predictably with any given record, but it occurs in one of every five GridFieldDetailForm views I make.
Itβs exactly one out of every five?
So the steps to reproduce are:
- Edit record
- Go back to grid
- Repeat five times
- On the fifth time, the prev/next buttons are incorrect