Closed imp-dance closed 4 years ago
Thank you for your pull request. I came across this specific case in my tests and the current behaviour is exactly that what i wanted. It should only set the checkbox to true when the actual value is the same as the provided one.
The reason is simple: The data what you can get from .formToJson should set exactly the same with .fillFormFromJsonValues.
Imagine when you swap checkboxes in dom and they have no specific array key like name=ids[]
than you definitely not want to set to true when the value doesnt match.
Maybe special value like boolean true/false could work as check/uncheck in this case but i'm not sure to add different behaviour depending on the value.
Fair enough, I just figured I'd let you know incase the behaviour wasn't expected. I saw that there were no checkboxes in the demo either, so I though it might've slipped between the gaps.
Nice catch. Thank you, i should add checkboxes to the demo as well. In the real TestSuite at https://brainfoolong.github.io/form-data-json/tests/test.html there are all possible inputs.
Describe the bug
FormDataJson.setInputValue()
seems to work like this in the case of checkboxes:inputElement.checked = value === inputElement.value
So, if the initial value is false, then
true === false
would returnfalse
.Expected behaviour
FormDataJson.setInputValue(input, true);
should set the input value totrue
.Actual behaviour
FormDataJson.setInputValue(input, true);
sets the input value tofalse
.To Reproduce https://codepen.io/schart/pen/gOaYOGQ
Proposed fix
Changing line 57 from
inputElement.checked = value === inputElement.value
to
inputElement.checked = value
Is this here on purpose, or is it a bug?