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

toggleState() for checkbox ? #1586

Closed
jeanpaulrichter opened this issue Jul 16, 2020 · 1 comment
Closed

toggleState() for checkbox ? #1586

jeanpaulrichter opened this issue Jul 16, 2020 · 1 comment

Comments

@jeanpaulrichter
Copy link

Hi!
I just stumbled upon the following: For a lot of (maybe all) components the documentation mentions the method toggleState() as a way "to interact with the input component" and gives i.e. the following example:

var checkbox = $(el).data('checkbox');
checkbox.toggleState();

if you look at the code you see for example in checkbox.js:

toggleState: function(){
    if (this.elem.disabled) {
        this.disable();
    } else {
        this.enable();
    }
},

At first I thought this was a simple line switch, but then I realized that this function is called by changeAttribute() in order to update the css classes when the element is disabled by the user. This means:

// works fine:
var el = $("#checkboxid");
el.prop( "disabled", !el.prop( "disabled" ) );
		
// makes no sense the way the code is written:
var checkbox = el.data('checkbox');
checkbox.toggleState();

Maybe I am misunderstanding somthing, but I believe contrary to what the documentation says enable(), disable() and toggleState() cannot be used "to interact with the input component", because they only make sense as internal functions.

In the case of checkbox the method indeterminate() also does not work, because it only changes the internal indeterminate option, but not the data-indeterminate attribute of the element.

@olton olton added the Discuss label Jul 25, 2020
@olton olton changed the title toggleState() problem toggleState() for checkbox ? Jul 25, 2020
@olton olton added this to the 4.4.0 milestone Jul 26, 2020
olton added a commit that referenced this issue Jul 26, 2020
…(indeterminate), `0` (unchecked), `1` (checked) or `undefined` (toggle between checked and unchecked), issue #1586
@olton
Copy link
Owner

olton commented Jul 26, 2020

in 4.4.0

  • Checkbox: add API method toggle( state ). The state must be -1 (indeterminate), 0 (unchecked), 1 (checked) or undefined (toggle between checked and unchecked)

@olton olton closed this as completed Sep 28, 2020
olton added a commit that referenced this issue Oct 28, 2023
…(indeterminate), `0` (unchecked), `1` (checked) or `undefined` (toggle between checked and unchecked), issue #1586
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