Semantic-UI icon indicating copy to clipboard operation
Semantic-UI copied to clipboard

[Form] `get values` behavior does not return logical value

Open ziaratban opened this issue 7 years ago • 4 comments

<div class="ui form">
  <div class="field">
    <div class="ui radio checkbox">
      <input type="radio" name="r1" value="0" checked>
      <label>Zero</label>
    </div>
    <div class="ui radio checkbox">
      <input type="radio" name="r1" value="1">
      <label>One</label>
    </div>
  </div>
  <div class="field">
    <div class="ui checkbox">
      <input type="checkbox" name="c1"  checked>
      <label>Check</label>
    </div>
  </div>
</div>
$('.ui.checkbox').checkbox();
console.log($('.ui.form').form('get values'));
$('input[name="r1"]').val('1');
$('input[name="c1"]').parent().checkbox('set unchecked');
console.log($('.ui.form').form('get values'));

Actual Result

Object { r1: false, c1: "on" }
Object { r1: "1", c1: false }

Expected Result

Object { r1: "0", c1:true }
Object { r1: "1", c1: false }

or

Object { r1: "0", c1:1 }
Object { r1: "1", c1: 0 }

Version

2.4.0

Testcase

http://jsfiddle.net/4eghqcrv/

ziaratban avatar Sep 29 '18 17:09 ziaratban

I find the same trouble.

“get values” returned "on" and false. but "set values" will not treat "on" as true...

landall avatar Apr 15 '20 15:04 landall

The radio value ("0" instead of false) was fixed in the community fork Fomantic-UI by https://github.com/fomantic/Fomantic-UI/pull/1328 See your adjusted jsfiddle here http://jsfiddle.net/lubber/gjLbqz5p/

However, providing the value for the checkbox is intented because you can specify a custom value for a checkbox input field and implemented by https://github.com/Semantic-Org/Semantic-UI/pull/2979

Related issue https://github.com/Semantic-Org/Semantic-UI/issues/2954

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-value

lubber-de avatar Aug 18 '21 08:08 lubber-de

The radio value ("0" instead of false) was fixed in the community fork Fomantic-UI by fomantic/Fomantic-UI#1328 See your adjusted jsfiddle here http://jsfiddle.net/lubber/gjLbqz5p/

However, providing the value for the checkbox is intented because you can specify a custom value for a checkbox input field and implemented by #2979

Related issue #2954

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-value

The unacceptable thing is the difference between "set vaules" and "get values".

landall avatar Aug 18 '21 14:08 landall

@landall I prepared a PR to also support "on" as a trigger to check the checkbox in the community fork Fomantic-UI by https://github.com/fomantic/Fomantic-UI/pull/2077

lubber-de avatar Aug 18 '21 15:08 lubber-de