Skip to content

Re-implement customisable alternating buttons #2022

@GuySartorelli

Description

@GuySartorelli

We used to have functionality to have buttons which have two states, a "default" and an "alternate". The save and publish buttons are examples of these - they say "saved" or "published" with a tick icon by default, but swap to "save" or "publish" with a more contextually appropriate icon when the form is dirty (i.e. there's unsaved changes).

The functionality used to allow for toggling the states manually, so it could be applied to custom actions and wasn't necessarily tied to the dirty state. This is documented in CMS 5 and earlier though it hasn't worked for some time.

In silverstripe/developer-docs#826 the documentation for this has been updated to the current state for CMS 6.2+.

We should reimplement:

  1. a way to toggle states of these buttons manually
  2. a way to say "this alternating button should not be affected by dirty state changes"
  3. Set the "initial" state in PHP?

Toggling states will be especially useful, since both silverstripe/linkfield and silverstripe/gridfieldextensions have custom hacky logic to toggle the publish button state. A proper JS api function to call would simplify these and reduce the chance of regressions.

Acceptance Criteria

  • Alternating button states can be toggled or set by calling a function in JavaScript
  • Alternating buttons can opt out (or in?) to being affected by form dirty state
  • There's a PHP API for setting the initial alternate state (could just be a data attr)
  • Docs are updated

TO DECIDE IN REFINEMENT

  1. Do we want a proper PHP API for this?
    • Would make it much easier to do
    • Would be weird since the PHP is in framework which is detached from the JS which is in admin
  2. Should being affected by dirty state be opt-in or opt-out?
    • Opt in is a better dev experience but might be a breaking change?
  3. Do we want to have a way to set the initial state?
    • That used to be part of the functionality
    • Could be useful for both custom and our functionality e.g. "if not published, initial state of publish button is the alternate state"

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions