Skip to content

Multiple Checkboxes field targeting single Schema Array #678

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

Closed
kyse opened this issue May 5, 2016 · 4 comments
Closed

Multiple Checkboxes field targeting single Schema Array #678

kyse opened this issue May 5, 2016 · 4 comments

Comments

@kyse
Copy link
Contributor

kyse commented May 5, 2016

I am noticing some undesired behavior when targeting a single array on my schema when using multiple fields of type checkboxes targeting that same array.

Plunker example: https://plnkr.co/u22GAXC6Fpwh1xOmm27Q

  • In the plunker, select a type from both dropdowns to expose the two checkboxes fields.
  • check one of the checkboxes on the top field, notice the model includes the object in the array properly.
  • check one of the checkboxes on the second checkbox field shown. The model will empty the array.
  • check one of the checkboxes on the second checkbox field again, and the array will get populated with the proper object, of course the original checkbox from the first checkboxes field will be missing and unchecked.

Would be nice to not have the array get cleared. Is there an option to make that happen by chance?

@Anthropic
Copy link
Member

Thanks for the plunker, the main issue would be using the same key for different sets of checkboxes, but the removal of the value when you select another I am not so sure of why that happens I would have expected it to replace it only.

I would use a unique key name and then add click event to handle merging the values into your required key. But I see your issue thanks to your plunker and agree it would be nice if a copyValueTo styled behaviour could handle updating an array of merged values.

@kyse
Copy link
Contributor Author

kyse commented May 6, 2016

If I comment out lines 2393 through 2400, and below that add:

                form.titleMap.forEach(function (item, index) {
                    var arrIndex = arr.indexOf(item.value);
                    if (arrIndex === -1 && vals[index])
                        arr.push(item.value);
                    if (arrIndex !== -1 && !vals[index])
                        arr.splice(arrIndex, 1);
                });

The issue seems to be resolved. However I haven't had time to play around with the test scripts you guys have so not sure if this would break anything else as a pull request. Also you appear to be in the middle of some refactoring with deprecated code. So will leave this here for now for feedback.

@Anthropic
Copy link
Member

You can still make a PR we plan to review all approved PRs to make sure they are working once the main split has been completed, that said if you can find the file in the webpack-babel branch it is worth checking that has the same code, if so then a PR would be fine if it is easy to migrate when ready.

@Anthropic
Copy link
Member

@kyse as your code suggestion is in the alpha I will close this, let me know if there is anything more you think needs doing on it :)

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

No branches or pull requests

2 participants