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.

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

W01F created an issue. See original summary.

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

gilmord’s picture

@W01F this module allows usage of the widgets.
There are a lot of core/contrib/custom widgets, some of them are complex (multi-fields, steps, conditions - like address field)
each one will require its own implementation of the "autosave" option.

For me, it looks like this should not be handled within this module

If it is - should we limit it with the core widgets only?
Or some simple widget types like checkbox, select list, radios?

Any thoughts on this?

sorson’s picture

I need exactly the same as @W01F .

How did you end up solving it?

I tried to hack something in with JavaScript, but it doesn't really work robust enough:

          $(document).on('change', 'input:checkbox', function(e) {
            $('.form-submit').mousedown();
          });

Is it anywhere in EditableFieldsForm.php if I would need to do this properly?

    // Update the entity.
    if ($component = $form_display->getComponent($field)) {
      $widget = $form_display->getRenderer($field);
      $items = $entity->get($field);
      $items->filterEmptyItems();
      $widget->extractFormValues($items, $form, $form_state);
      $entity->save();
    }
gilmord’s picture

Hi @sorson
you can check these two modules on how they implement auto-submit functionality
I am planning to add a similar implementation to this one on some point, but I do not have a timelines yet

https://www.drupal.org/project/views_autosubmit
https://www.drupal.org/project/better_exposed_filters

w01f’s picture

I suppose a hacky way could be to display a view output of the fields on the node display instead of the actual fields, and then either the ajax update option for the editable field in the view output (I haven't tested but it sounds like that works) would likely work - or there's another module (Views Entity Form Field) that might also work.

But both of these options are obviously less straightforward than if there's a direct ajax submit field option for the regular node field display using editable field widget.

rodrigoaguilera’s picture

Status: Active » Needs review
StatusFileSize
new2.76 KB

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.

rodrigoaguilera’s picture

StatusFileSize
new3.95 KB

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

gilmord’s picture

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

rodrigoaguilera’s picture

gilmord’s picture

Status: Needs review » Fixed

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

Thanks!

gilmord’s picture

Status: Fixed » Closed (fixed)
tonka67’s picture

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.

alfthecat’s picture

@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.

gilmord’s picture

Views field configuration:
Views Configuration

Result:
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
- set up some really simple example, use a fresh view with only node title, and configure it like on my screenshots above
- use Inspect Element in browser developers tools and check the event is attached to the field in the view
example
- 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"

alfthecat’s picture

@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.

tonka67’s picture

@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?