How to make radio button selected/checked using yaml?
Closed this issue · 6 comments
How to make radio button checked using yaml?
There is no answer to this in the doc's found here: https://octobercms.com/docs/backend/forms#field-radio
However, looking at the code in the main repo found here: https://github.com/octobercms/october/blob/master/modules/backend/widgets/form/partials/_field_radio.htm#L22
Says that October is looking for: $field->isSelected($value)
Questions:
-
Is there a way to make a radio option
selected / checked
via yaml. -
If so then can we add the information to the doc's.
-
I believe I had the same issue with checkboxes a while ago and suggested we should update the doc's also for making them
checked
via yaml.
Cool, I'll wait for a reply (not going to tag admins as I know everyone's busy).
@ayumi-cloud Try default: true
in the YAML config.
@bennothommo Hi thanks for your suggestion, sorry if I'm being a bit thick! I'm not sure how the default: true
would work in this situation.
I give more information and see what your thoughts are on this:
example:
type: radio
options:
one: One
two: Two
(The option two is checked="checked"
at the start in the form field).
Let's say for example we want the following to be setup from the start:
We are under the impression that this can't be done through yaml at the moment. Instead we set this up using a seeder file instead.
Please correct me if I'm wrong!
So I was thinking of adding this information to the doc's.
@ayumi-cloud radio buttons work the same as dropdowns
example:
type: radio
default: one
options:
one: One
two: Two
Ah now I see and get what you both are saying! Sorry language barrier when I read the:
default | specifies the default value for the field.
To me it makes better sense saying something like:
default | specify the 'value' field in the options list you want to make selected or checked on page load.
[edit] The bit that was confusing me was the word value
I thought you meant true
or false
and not value
or key
fields in the options list.
Also can I add your code example in the doc's in the previous comment with the default
field.
Please consider my request as I'm thinking about Newbie people reading the doc's for the very first time and not seasoned users.
@ayumi-cloud Sorry my bad, I misread your original post to mean "checkbox", not radios. @LukeTowers' answer is the correct one here.
Fixed in #434