Autosave option for editable node fields?

Created on 9 December 2021, about 3 years ago
Updated 31 August 2024, 4 months ago

I see quite a few (older) issues regarding an autosave functionality for views, but it would be great to have an autosave for nodes as well. My use case is I have several taxonomy select lists that the user would simply be able to click and select, instead of clicking > selecting > and then needing to hit update.

โœจ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States w01f

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain rodrigoaguilera Barcelona

    I implemented something similar to #4 that works for select list fields by triggering the submit when the input changes. Maybe the event, "change" in this case, should be configurable.

    I tried to attach an #ajax callback to the select field in the render array but that didn't add any event to the
    element.

    Attached is a patch against 1.0.1.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain rodrigoaguilera Barcelona

    Attached is an improved version that allows for changing the event that is triggered.

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine gilmord ๐Ÿ‡บ๐Ÿ‡ฆUkraine

    Hi @rodrigoaguilera can you please create a fork and open a merge request based on your patch?
    Thanks!

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine gilmord ๐Ÿ‡บ๐Ÿ‡ฆUkraine

    This is far from perfect, but at least something
    It works for the simple cases, and should be a good starting point

    Thanks!

  • Status changed to Fixed 11 months ago
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine gilmord ๐Ÿ‡บ๐Ÿ‡ฆUkraine
  • It looks like this feature was committed, but I'm at a loss as to how to use it.

    I see that two new fields appear in the views field settings:

    1. Fields that trigger an ajax submit when they change (autosave)
    2. Event that will trigger an ajax submit for the fields above

    Adding anything at all to the first field causes the update button to hide, but I can't get the field itself to update. What is the correct syntax?

    Does something else need to be configured, or is there an additional missing patch? Should the view's Ajax be on or off? Some direction would be appreciated.

  • ๐Ÿ‡น๐Ÿ‡ญThailand AlfTheCat

    @tonka67 It seem like autosave is not working in views. Best result I can get is to use ajax in the view and hit tab and then enter, after typing a value in the editbale field. This updates the field. I tried "blur" and "change".

    If autosave for views is broken then a new issue should be opened as this one is closed and maybe only targeted nodes/entities.

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine gilmord ๐Ÿ‡บ๐Ÿ‡ฆUkraine

    Views field configuration:

    Result:

    The "Fields that trigger ajax" - this is array keys of the widget form, you can check here how it is used:
    https://git.drupalcode.org/project/editablefields/-/merge_requests/13/di...

    And the "Event that will trigger an ajax" - is a javascript event to be bind to trigger submit

    @tonka67 a few things to check:
    - make sure you use the latest dev version of the module
    - use Inspect Element in browser developers tools and check the event is attached to the field in the view

    - if the event IS there and does not work - check the javascript console output, maybe there are some errors
    - if the event IS NOT attached - please use xdebug or any other way to debug the inside of "foreach ($fields_ajax as $field_ajax) {" loop to check if the value you set in "Fields that trigger ajax" is in the $form

    One more thing - for the cases when the entire view is wrapped in a form element (for example if you use Views Bulk Operations) you have to set the "Select behavior" of the field to "Form in popup" instead of the default "Inline form"

  • ๐Ÿ‡น๐Ÿ‡ญThailand AlfTheCat

    @gilmord thank you very much for the guidance, I now managed to get it working. I was using {{ title }} and when that didn't work, I tried [title]. Using title made it work.

    Perhaps out of scope, but is there a way to also ajax-refresh the view so that totals and other, non-editable field values update as well? In my case, I have a view of line items that have an editable quantity field, and non-editable line item total fields and then there is a sub-total aggregated value as well.

  • @gilmord it took me longer than expected to loop back around to this.

    On testing I can get the Title field to work perfectly, but the body field, which has a ckeditor attached to it, does not register the ajax at all.

    Are long, formatted text fields set up differently?

Production build 0.71.5 2024