Mithril.js: checkbox 'checked' attribute

Created on 8 Jun 2018  路  2Comments  路  Source: MithrilJS/mithril.js

why checkbox isn't checked after 1 second? all examples i found is using m.prop but its deprecated? i need this to preset user settings

var state = false
var Cheeeck = {
    oninit: ()=> {
        setTimeout(() => {
            state = true
        }, 1000);
    },
    view: () => {
        return m('input', {type: 'checkbox', checked: state})
    }
}
m.mount(document.body, Cheeeck)

Most helpful comment

Mithril's auto-redraw system doesn't work with setTimeout so you have to insert an m.redraw() statement after you update state:

var Check = {
    oninit: ()=> {
        setTimeout(() => {
            state = true;
            m.redraw();
        }, 1000);
    },
    ...
};

Auto-redraw only kicks in for DOM event handlers, after m.request's complete, and after m.route changes. For everything else, you need to call m.redraw() yourself.

See The auto-redraw system doc for more details.

All 2 comments

Mithril's auto-redraw system doesn't work with setTimeout so you have to insert an m.redraw() statement after you update state:

var Check = {
    oninit: ()=> {
        setTimeout(() => {
            state = true;
            m.redraw();
        }, 1000);
    },
    ...
};

Auto-redraw only kicks in for DOM event handlers, after m.request's complete, and after m.route changes. For everything else, you need to call m.redraw() yourself.

See The auto-redraw system doc for more details.

Thank you! i know about this API and lost hour even didn't think to try it T_T

Was this page helpful?
0 / 5 - 0 ratings

Related issues

simov picture simov  路  4Comments

omenking picture omenking  路  3Comments

designMoreWeb picture designMoreWeb  路  4Comments

andraaspar picture andraaspar  路  4Comments

marciomunhoz picture marciomunhoz  路  4Comments