Closed (fixed)
Project:
Views Fields On/Off
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
22 Mar 2019 at 18:56 UTC
Updated:
18 Mar 2022 at 02:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
andileco commentedHere's a stab, which will also work with https://www.drupal.org/project/views_fields_on_off/issues/3048250 (although we may want to update this after that one goes in so as to have a default state radios (I'm thinking maybe a "All" option selected)).
Comment #3
andileco commentedLast one wasn't working in some cases after submitting. I think this one should work.
Comment #4
franksj commentedSetting
['#attributes']['checked']isn't a totally valid way to do this. I know that['#default_value']doesn't work as expected for an exposed form, but here's a case where['#attributes']['checked']doesn't work:Create a view on Article with the following fields:
Content: Title
Content: Authored by (Authored by)
Content: Authored on (Authored on) [hidden]
Content: Body (Body)
Content: Content type (Content type)
Content: ID (ID) [hidden]
Content: Tags (Tags)
Global: On/Off Form (On/Off Form)
The On/Off Form only allows selection of visible fields (and I'm not sure when it started doing that - I thought that previously, it allowed selection of fields whether they were visible or not, which I think it should do), so leave them all visible. Select all of the fields in the On/Off form, then edit "Authored on" to Excluded.
Now, when you go to the view, all of the fields are checked, even though "Authored on" isn't visible. We need to be able to set the checked fields individually. I started working on this and found that
['#default_value']didn't work as expected in the exposed form.For instance, if you create a standard form and display it, this behaves correctly:
If you paste that into the exposed form, the default value for a
checkboxeselement is ignored (note that#default_valueworks for other controls on an exposed form, and that it works for checkboxes on another form, but for checkboxes on an exposed form, it doesn't work). If we can't use the default value or attributes for the whole checkboxes element, we need some other way to check them individually. I don't have that other way yet :)Comment #5
franksj commentedSo we don't lose this experiment for testing:
If we add the code above to a regular form, then the "Two" checkbox will be selected by default, and the "Three" option will be selected by default.
If we add this code to the exposed form, then the checkboxes are all un-checked and the "Three" option will be selected by default.
Comment #6
franksj commentedComment #7
ranavaibhav+1 still in scope?
Comment #8
andileco commentedYes, still in scope, and the patch should work if you need a quick fix.
Comment #9
maxilein commentedComment #12
andileco commentedThis commit adds a checkbox: "Enable fields by default." - if this is checked, the checkboxes and multi-select fields will be shown with all the items selected (I skipped this for radios and single-select because it wouldn't make sense to show them as selected when more fields are showing than can be selected for these select types).