knockout js radio button click event reset selection

knockout js radio button click event reset selection

Asked on December 22, 2018 in knockout js.
Add Comment


  • 3 Answer(s)

        From the information of  click event documentation: :

     

        By default , Th e Knockout is stop  the click event from starting any default action .

        However, if the default click action want to proceed, just send back true from the click handler function.

       So That, The radio button is reset due to the click handler and for fix this the user can sent back true at the end:

    click: function(){
        alert('Hi');
        return true;
    }
    

    Answered on December 22, 2018.
    Add Comment

        Basically, The  click handler is not result in catching  which should be retain the value.

        The handler  is going back  to default after the user select an item .

    So try this code :

    return true;
    

        As the only code in their handler.

    Answered on December 22, 2018.
    Add Comment

        Eliminate  the click event or use sent back true from click event . Because Knockout stop  the click event from taking any default action .

        This means that if the user use the click binding on an a tag ,For ex: The browser is call only the handler function and will not navigate to the link’s href

    var viewModel = {
        wantsSpam: ko.observable(true),
        spamFlavor: ko.observable('cherry'),
        /*click: function(){
            alert('Hi');
        }*/
    };
    

        Or use it like this :

    var viewModel = {
        wantsSpam: ko.observable(true),
        spamFlavor: ko.observable('cherry'),
        click: function(){
            alert('Hi');
            return true;
        }
    };
    
    Answered on December 22, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.