user3406423
user3406423

Reputation: 11

Dart checkbox, force check

I'd like to ask if there is any method for forcing CheckBox to check. I've tried to use Click();, but without success. I was searching for something like .setChecked(true); but again no success. Is it because I'm using checkbox as InputElement?

void main() {
    InputElement ac = querySelector('#ac');  //Checkbox id="ac"
    Storage localStorage = window.localStorage; 
    String sAc = localStorage['ac'];
    if (sAc == '1') {
        ac.Click();
    }

    ac.onClick.listen((Event e){
        String status;
        if (ac.checked){
            status = '1';
        }
        else
        {
            status = '0';
        }
        localStorage['ac'] = status;
    });   
}

Upvotes: 1

Views: 117

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 658027

var cb = (document.querySelector('#ac') as CheckboxInputElement);
cb.checked = true;

Upvotes: 1

Related Questions