lundi 18 juin 2018

Using Semantic UI: use ajax response for checkbox beforeChecked function

I want the checkbox to post everytime it is check and uncheck, but validate if it is successful or fail before changing itself. Semantic UI has beforeCheck function that can return false to prevent changing, but writing it like this doesn't work, is there a way to return false from ajax for this to work?

$('.ui.checkbox').checkbox({
        beforeChecked: function(){
            let chapterInfo = {
                isHidden: false
            }
            var f = $.post("editnovel", {
                novel: chapterInfo
                }).done(function( data ){
                    return true
                }).fail(function( data){
                    return false
                })
        },
        beforeUnchecked: function(){
            let chapterInfo = {
                isHidden: true
            }
            return $.post("editnovel", {
                novel: chapterInfo
                }).done(function( data ){
                    return true
                }).fail(function( data){
                    return false
                }
            )
        }
    });




Aucun commentaire:

Enregistrer un commentaire