Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to remove specific custom buttons by label #4498

Merged
merged 7 commits into from Dec 7, 2017

Conversation

schilgod
Copy link
Contributor

Creating new PR as old PR #4219 was closed.
@rmehta Hope that you will accept this.

Some reasons this PR is helpful,

  1. This will make the code in custom apps cleaner and any changes on Frappe wont affect custom apps in future, if any.
  2. This is useful when we need to remove one or more buttons, but not all.
    For example, in Material Request, currently we don't need the buttons under "Make", but we do need Stop button. We also have a custom button for creating Purchase Order(s) for items w.r.t Supplier, not a single Supplier as is case now.
  3. Allows to show/hide buttons based on permissions.

Function to remove custom button by label

Example :

  1. In Material Request, to remove "Stop" button, can be achieved by calling function as below,
    frappe.ui.form.on("Material Request", {
    onload: function(frm) {
    var buttons = [ [ "Stop", "" ] ];
    frm.remove_custom_button(buttons);

     //OR
     //var buttons = [ [ "Stop" ] ]; (since it's not inside group of buttons.)
     //frm.remove_custom_button(buttons);
    

    }
    });

screenshot from 2017-09-30 10-54-40

  1. In Material Request, to remove "Purchase Order" button, can be achieved by calling function as below,
    frappe.ui.form.on("Material Request", {
    onload: function(frm) {
    var buttons = [ [ "Purchase Order", "Make" ] ];
    frm.remove_custom_button(buttons);
    }
    });

screenshot from 2017-09-30 10-49-36

  1. Remove multiple buttons,
    frappe.ui.form.on("Material Request", {
    onload: function(frm) {
    var buttons = [ [ "Purchase Order", "Make" ], [ "Supplier Quotation", "Make" ] ];
    frm.remove_custom_button(buttons);
    }
    });

screenshot from 2017-09-30 10-53-16

@netchampfaris
Copy link
Contributor

netchampfaris commented Dec 4, 2017

@schilgod

To remove a simple custom button, I have to use
frm.remove_custom_button([['Close']]).

Can we make it more API friendly?

For example, these should work:

frm.remove_custom_button('Close');

frm.remove_custom_button('Purchase Order', 'Make');

frm.remove_custom_button(['Purchase Order', 'Sales Order'], 'Make');

@netchampfaris netchampfaris merged commit a247dfe into frappe:develop Dec 7, 2017
@schilgod
Copy link
Contributor Author

schilgod commented Dec 8, 2017

thanks @netchampfaris

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants