lewisjenkins / craft-dynamic-fields

Populate Craft fields with dynamic data using the power of Twig.
Other
147 stars 11 forks source link

Radio Button Default does not work #13

Closed martinherweg closed 7 years ago

martinherweg commented 7 years ago

If I add the default: true option the Button don't gets the :checked Status.

The Code in my Radio Button field looks like this.

{% set predefinedColors = [
{
    "name": "Rot",
    'value': 'o-colors--guardsmen_red',
    'default': false
},
{
    'name': 'Orange',
    'value': 'o-colors--gold_drop',
    'default': false
},
{
    'name': 'Grün',
    'value': 'o-colors--wasabi',
    'default': false
},
{
    'name': 'Blau',
    'value': 'o-colors--deep_cerulean',
    'default': false
},
{
    'name': 'Lila',
    'value': 'o-colors--violet_eggplant',
    'default': false
},
{
    'name': 'Dunkel Grau',
    'value': 'o-colors--cod_gray',
    'default': true
},
{
    'name': 'Grau',
    'value': 'o-colors--gondola',
    'default': false
},
{
    'name': 'Medium Grau',
    'value': 'o-colors--mine_shaft',
    'default': false
},
{
    'name': 'Hell Grau',
    'value': 'o-colors--mercury',
    'default': false
},
] %}

{% for color in predefinedColors %}
    {"value": "{{ color.value }}", "label": "<span class='color__chooser {{ color.value }}'></span>"
  {% if color.default%} ,"default": true{% endif %}}
  {% if not loop.last %},{% endif %}
{% endfor %}

Is there a mistake in the Code or is default not working with Radio Buttons?

Thanks.

lewisjenkins commented 7 years ago

Your code above is working for me. I cut and pasted it into a Dynamic Radio field, and got the following result:

screenshot 2017-01-11 14 27 22

martinherweg commented 7 years ago

The Issue is just with existing Fields, sorry didn't tested it with new ones.

Closing the Issue, thanks :)