Problem/Motivation

The top bar is being built in #3402046: Create the Top Bar with the minimum functionality: the local actions from entity form. This issue is aimed to move the Save button into that top bar (for Entity forms only, at least for now).

Proposed resolution

To define.

References to make it accessible:

Remaining tasks

Code review

User interface changes

Before:

before

After:

after

API changes

None

Data model changes

None

Issue fork drupal-3408500

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Issue fork navigation-3408500

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ckrina created an issue. See original summary.

m4olivei’s picture

Title: [PP1] Move the Save button into the Top Bar » Move the Save button into the Top Bar
m4olivei’s picture

Issue tags: +frontend, +backend

kostyashupenko made their first commit to this issue’s fork.

finnsky’s picture

We had rude prototype for top bar elements.
https://www.drupal.org/project/navigation/issues/3398483

Probably css and markup of it can be reused

kostyashupenko’s picture

Just my thoughts.
1. Each form can have several submit buttons, i.e.: Save, Preview, Something else? Which means we can't just use `for` html attribute with form_id attribute value.
2. Instead we could use somekind of

  <label for="edit-submit" tabindex="0">Preview</label>
  <label for="edit-submit--2" tabindex="0">Save</label>
  <label for="edit-submit--3" tabindex="0">Something else?</label>

The solution above is already working, but i don't think it's too much accessible honestly, correct me if i'm wrong.

3. Non else "native" solutions are working.
4. Potentially we could use javascript for this. For everything: creation of the "fake" submit buttons in top bar and for binding listeners.

Few more thoughts but about other thing:
1. I think this task should be not only about moving "Save" button in top bar, but instead we should move all actions of the form in top bar.
2. On which pages we should do this trick? In Drupal there are many pages in admin back office with lots of forms, which has actions. I bet for any admin page where we have form, isn't it ?
3. Potentially one admin page can contain two or more forms (but i can not be sure here) - obviously we shouldn't move all actions from all forms in top bar. What to do in that case?

kostyashupenko’s picture

Issue tags: +W3C validation
ckrina’s picture

Issue summary: View changes

Answers to #6:

Each form can have several submit buttons

Ideally, we shouldn't have several Submit buttons. The other ones should be regular buttons and/or links.

The solution above is already working, but i don't think it's too much accessible honestly, correct me if i'm wrong.

See the link on the summary to Stackoverflow where explains that the main button with the attribute form should be enough to associate a button to a form-owner in modern web browsers (the ones supported by core).

Other thoughts:

1.I think this task should be not only about moving "Save" button in top bar, but instead we should move all actions of the form in top bar.

Not really: we'll probably more the Delete action somewhere else more hidden to leave more space in the top bar.

2. On which pages we should do this trick? In Drupal there are many pages in admin back office with lots of forms, which has actions. I bet for any admin page where we have form, isn't it ?

This should only happen on Entity forms for now.

3. Potentially one admin page can contain two or more forms (but i can not be sure here) - obviously we shouldn't move all actions from all forms in top bar. What to do in that case?

Exactly! That's why we should move it only for Entity forms now. I forgot to add it in this specific issue. I've updated the form.

finnsky’s picture

Gonna add POC MR

finnsky’s picture

StatusFileSize
new80.84 KB

Main idea to use form attribute https://dev.to/dailydevtips1/submit-button-outside-the-form-2m6f

Claro buttons has margin so not looking good OOB. :)

We can create custom button button in fact and hide original one.

ckrina changed the visibility of the branch 3408500-move-the-save to hidden.

ckrina’s picture

Status: Active » Needs work

Needs rebase :)

kostyashupenko’s picture

MR rebased

Seems submit is working fine in top bar. But i'm thinking that maybe we shouldn't move original submit, but instead - duplicate? I find it unclear when i'm scrolling down the page and there is no "Save" button in the bottom.

kostyashupenko’s picture

Status: Needs work » Active

ckrina’s picture

Status: Active » Needs work
StatusFileSize
new40.26 KB

Thanks @kostyashupenko! I left a few comments in the MR plus:

This should be removing any default margin the button has to it's adjusted to the top bar and looks minimally OK:

I find it unclear when i'm scrolling down the page and there is no "Save" button in the bottom.

I totally understand this, and the reason is that you're used to find the button there. We discussed this and having the button in 2 places didn't work. We're basically trying to do a change of paradigm here on full page forms.

finnsky’s picture

Better to duplicate button then.

We may create Drupal.theme.toolbarButton = () => {}

Or what i personally prefer use web component for this:
https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_te...

ckrina’s picture

Project: Navigation » Drupal core
Version: 1.x-dev » 11.x-dev
Component: Code » navigation.module
aaronmchale’s picture

Don't get me wrong, I love the idea here. The challenge we have to consider, I think, is that we would then have the form submit button in very different locations depending on which form you're using.

For instance, if you're on the node edit form you would Save by going to the top right of the screen, but then if you go to a configuration form, you would save by going to the bottom left of the screen, that feels a bit too inconsistent.

There's also the question of whether this is follows form design best practice, the user generally expects to start at the top of the form and work their way down until they get to the bottom where they expect to find the submit button. I suspect (although we would need to test this), that users might find this change challenging, especially users who use magnification software so cannot see the entire screen at once.

Gauravvvv made their first commit to this issue’s fork.

nayana_mvr made their first commit to this issue’s fork.

nayana_mvr’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new511.38 KB
new286.68 KB
new275.51 KB
new276.08 KB

Changes in MR!169 are not getting applied in Drupal 11.x. Getting the following error:-

Checking patch js/form-actions.js...
Checking patch navigation.libraries.yml...
error: navigation.libraries.yml: No such file or directory
Checking patch js/form-actions.js...

Tried to apply the changes of MR!7943. Changes applied cleanly but getting console error.

7943

I have created a new MR!9516 incorporating review comments of MR!169. I have placed all the action buttons in top bar otherwise it will be confusing for the editors imo. This is currently working for node edit form, media edit form and taxonomy term edit form.

after-fix

Regarding,

the user generally expects to start at the top of the form and work their way down until they get to the bottom where they expect to find the submit button.

I think placing the action buttons in top bar is useful so that editor can save the form immediately after editing a field instead of scrolling down the whole form (E.g., if editor needs to edit just the first field value.). Also, top bar is currently available only on entity edit forms. When user is creating a new node/ term/ media, the save button will be in the bottom itself.

Kindly review the changes. Thanks.

finnsky’s picture

@nayana_mvr, original function was written with vanilla js. Is there any special reason to use jQuery?

nayana_mvr’s picture

@finnsky No specific reason. jQuery is my primary language. If required, I will re-write it in vanilla js.

finnsky’s picture

Better to avoid jQuery in core contributions. You can find lot of issues in Drupal core about removing jQuery. So new code may contain it only if special reason exists

nayana_mvr’s picture

Thanks @finnsky for the information. I will be careful about that in future. I have update the code using vanilla js. Kindly review.

finnsky’s picture

Status: Needs review » Needs work

Few more ideas we can implement there.

1. We can not copy all buttons with original classes.
Because they contain unexpected styles. Probably it is better to create new buttons with document.createElement('button') there and copy original buttons attributes like https://codepen.io/finnsky/pen/qBzGNoZ?editors=1010

2. We can use existing toolbar button component for that copied buttons. Here you can see idea, https://thunderous-treacle-600c5c.netlify.app/?path=/story/page--basic (Styles can be outdated, this is old POC)

3. Classes for that buttons can be based on button type. Let's say button type="submit" is primary and other buttons just basic.

4. Here you may see original comment https://git.drupalcode.org/project/drupal/-/merge_requests/9516/diffs#71...

We need to do research in Drupal core forms. and find common selector logic for them. I believe should be something. But i'm not sure.

Thank you for participating

nayana_mvr’s picture

StatusFileSize
new352.77 KB
new3.44 KB

@finnsky I have attempted your suggestions and created a patch. Following are the changes done based on the suggestions:-

  • Created new buttons when 'type=submit' which are 'Save' and 'Preview' buttons in case of node edit form. For 'Delete' action, I cloned the element as it is as I was not sure if it needs to be changed to <button>.
  • Copied all attributes except 'class' from original buttons to new buttons and added new classes 'toolbar-button toolbar-button--primary' to the new buttons since both buttons have 'type=submit' (Referred class names from https://thunderous-treacle-600c5c.netlify.app/?path=/story/page--basic).
  • Placed the new buttons and Delete link in the top-bar.

This is how the buttons look like now:-

buttons

Regarding the original buttons, should we just hide them from the UI or remove them completely once new buttons are created?

This is just an attempt based on my understanding. As mentioned in previous comment, this may require more research on Drupal core forms.

finnsky’s picture

Sorry, but why patch? before you sent it as MR

nayana_mvr changed the visibility of the branch 3408500-move-save-button-to-topbar to hidden.

nayana_mvr changed the visibility of the branch 3408500-move-save-button-to-topbar to active.

nayana_mvr’s picture

@finnsky Sorry for the confusion. Since there could be more changes, I thought creating patch would be better than directly committing to the MR. I have now committed the changes to MR!9516. Please check.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.