[Guide] Add a different class to a custom button

So I added a custom button but needed it to be blue like the primary button. cur_frm.add_custom_button does not have a provision to set your own button class. I was able to do this with a little jQuery after adding the button.

refresh(frm) {
    cur_frm.add_custom_button( __('Button Name'), 
        function(){
    	    //do something when the button is clicked
    	}
    );
    //the button selector is the button label separated by %20 (space)
    //we then remove the unwanted class and add the desired one
    $("button[data-label='Button%20Name']").removeClass("btn-default").addClass("btn-primary");
}
1 Like