Browse Source

[Docs] Added new article to add custom button to a form (#2364)

version-14
Shreyas Patil 8 years ago
committed by Rushabh Mehta
parent
commit
8cb27f8366
2 changed files with 27 additions and 0 deletions
  1. BIN
      frappe/docs/assets/img/app-development/add_custom_button.png
  2. +27
    -0
      frappe/docs/user/en/guides/app-development/adding-custom-button-to-form.md

BIN
frappe/docs/assets/img/app-development/add_custom_button.png View File

Before After
Width: 1918  |  Height: 644  |  Size: 88 KiB

+ 27
- 0
frappe/docs/user/en/guides/app-development/adding-custom-button-to-form.md View File

@@ -0,0 +1,27 @@
To create a custom button on your form, you need to edit the javascript file associated to your doctype. For example, If you want to add a custom button to User form then you must edit `user.js`.

In this file, you need to write a new method `add_custom_button` which should add a button to your form.

#### Function Signature for `add_custom_button(...)`
frm.add_custom_button(__(buttonName), function(){
//perform desired action such as routing to new form or fetching etc.
}, __(groupName));

#### Example-1: Adding a button to User form
We should edit `frappe\core\doctype\user\user.js`

frappe.ui.form.on('User', {
refresh: function(frm) {
...
frm.add_custom_button(__('Get User Email ID'), function(){
frappe.msgprint(frm.doc.email);
}, __("Utilities"));
...
}
});

You should be seeing a button on user form as shown below,

![add_custom_button_screenshot](/assets/img/app-development/add_custom_button.png)

<!-- markdown -->

Loading…
Cancel
Save