If I am using the following to create a custom fieldset (of "advanced" settings) on a theme setting form:
function theme_form_system_theme_settings_alter(&$form, &$form_state) { $form['advanced'] = array( '#type' => 'fieldset', '#title' => t('Advanced Settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); }
Can I have BackdropCMS remember whether the fieldset that defaulted to closed has been opened by a user and have it opened by default on the next visit?
Basically, I want it to remember whether it was open or closed at the time the form was saved and then default to that same state the next time the form is opened.
How do I do this?
Comments
I do not think that you can do this currently. If you are willing to write some code to get this working, you can create some Javascript to track the state for each user on each field. You could save this in Local Storage on the browser, or you could use a couple of AJAX callbacks to handle the saving/loading of data.
There are a couple of interesting issues about field sets that I found for Drupal:
https://www.drupal.org/project/drupal/issues/65578
https://www.drupal.org/project/drupal/issues/1168246
There is also a contrib module that may provide what you are looking for:
https://www.drupal.org/project/fieldset_helper
This has been discussed before. We are currently making certain assumptions re which form elements are important or not, and are accordingly setting fieldsets to be collapsible or not, and also collapsed by default or not. We are right about most of these, but to be sure, we'd need to have usage metrics (and capture individual fieldset states - which can be a lot).
I think that the best approach to have each fieldset collapsible state be remembered on a per-user basis, would be to store it in SESSION or cookies.
AJAX should help with saving/remembering the state of fieldsets when the the form is not saved.
I was thinking that it might be possible to use a variable for the "#collapsed" state and update it on form submit?