Form Actions through custom Button

Hello guys

I wish to add 2 custom buttons to the leave application.
namely “Approval” & “Rejection”.

While clicking approval the status wants to change “Approved” and form submit

and while clicking the Reject button
status want to change "Rejected " and form make submit.

this is my code to add the custom buttons

 refresh(frm)
 {
  cur_frm.add_custom_button(__("Approve")).css({'color':'white','background- 
  color':'yellowgreen','font-weight': 'bold'}) ,


cur_frm.add_custom_button(__("Reject")).css({'color':'white','background-color':'red','font-weight': 'bold'});


 },

Is there any option to make this?

Please help me with this

1 Like

Hi @jinsy,

Please apply it.

frappe.ui.form.on("Leave Application", "refresh", function(frm) {
    
    frm.add_custom_button(__("Approve"), function(){
        frm.set_value('status',"Approved");
        frm.refresh_field('status');
        frm.save('Submit');
    }).addClass("btn-success").removeClass("btn-default");
    
    frm.add_custom_button(__("Reject"), function(){
        frm.set_value('status',"Rejected");
        frm.refresh_field('status');
        frm.save('Submit');
    }).addClass("btn-danger").removeClass("btn-default");
    
});

Then Reload and check it, please.

Thank You!

2 Likes

Thank you @NCP
That works ! Appreciate your help! Thanks