cms icon indicating copy to clipboard operation
cms copied to clipboard

Save always config field

Open niktwenty3 opened this issue 3 years ago • 1 comments

The idea is to create a "Save always" configuration field that when it is true saves the field's value regardless of visibility settings. This setting could be used in fields that a "Select" or "Button group" controls their visibility, essentially giving the user the capability to create "faux-tabbed" content.

Save_always_field

I've done a tiny bit of leg work and figured out on my own where I could add this option so that it can be displayed on the backend, but, since I have not worked with Laravel before, it's probably just a tiny step.

Still, to add the button on my end I added the following code in cms/src/Http/Controllers/CP/Fields/FieldsController.php after visibility.

            'save_always' => [
                'display' => __('Save always'),
                'instructions' => __('statamic::messages.fields_save_always_instructions'),
                'type' => 'toggle',
                'validate' => 'boolean',
                'width' => 33,
            ],

And for the message I just edited cms/resources/lang/en/messages.php and added 'fields_save_always_instructions' => 'Save field value always regardless visibility status.', after fields_visibility_instructions.

My next goal is to try and understand how Entries are saved/validated to potentially offer a patch for this.

niktwenty3 avatar Jul 27 '22 10:07 niktwenty3

We've talked about adding config for this, figured it would come up at some point! Feel free to give this PR a whirl 👍

Save field value always, regardless of visibility status.

^ I tweaked the config instructions in your example though, as the hidden option in the Visibility drop down doesn't affect actually data flow at all. This is more to override data flow behaviour on conditional fields.

jesseleite avatar Jul 27 '22 20:07 jesseleite