Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A value of '_unchecked' is always in the array #589

Closed
abbott567 opened this issue Aug 22, 2018 · 3 comments
Closed

A value of '_unchecked' is always in the array #589

abbott567 opened this issue Aug 22, 2018 · 3 comments

Comments

@abbott567
Copy link
Contributor

I've been using the checkboxes component but when looping through values in the view, but there's always an additional one called '_unchecked'. If I turn off Javascript it doesn't happen. It seems to be getting added by the autostore.

For example, using this macro:

{{ govukCheckboxes({
  idPrefix: "test",
  name: "test",
  fieldset: {
    legend: {
      text: "Test checkboxes",
      isPageHeading: true,
      classes: "govuk-fieldset__legend--xl"
    }
  },
  items: [
    {
      value: "singleValue",
      text: "Check this single value"
    }
  ]
}) }}

and this loop in the view:

{% for items in data.test %}
    {{ item }},
{% endfor %}

Then on the page it would render: _unchecked,singleValue

$input.attr('value', '_unchecked')

@colinrotherham
Copy link
Contributor

colinrotherham commented Aug 28, 2018

Hi @abbott567,

Like me, you're also using <input name="parent[child]"> nested fields aren't you?
I can reproduce your issue when I do the same.

The storeData() code in ./lib/utils.js doesn't work with _unchecked here. It only removes the value at the top level, ignoring it when nested like yours.

The fix? I've patched it with the nested fields pull here: #573

One for @joelanman too?

Thanks

@abbott567
Copy link
Contributor Author

Yeah this was exactly my issue. The PR you’ve done looks super comprehensive! 🙌

@36degrees
Copy link
Contributor

I believe this was closed in #573 – please feel free to re-open if I'm wrong about that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants