add_view_button¶
- add_view_button(text, options)¶
domain: client
language: javascript
Description¶
Use add_view_button
to dynamically add a button in the view form.
This method is usually used in the on_view_form_created
events.
The following parameters are passed to the method:
text
- the text that will be displayed on the buttonoptions
- options that specify additional properties of the button
The options
parameter is an object that may have following attributes:
parent_class_name
is a class name of the parent element, the default value is ‘form-footer’btn_id
- the id attribute of the buttonbtn_class
- the class of the buttontype
- specifies the type (color) of the button, it can be one of the following text values:primary
success
info
warning
danger
image
- an icon class, one of the icons by Glyphicons from http://getbootstrap.com/2.3.2/base-css.htmlsecondary
: if this attribute is set to true, the button will be right aligned if Buttons on top attribute of the View Form Dialog is set, otherwise left aligned.expanded
- if set to true the button will have class ‘expanded-btn’ and that defines its min-width to 120px, default true
The method returns a JQuery object of the button.
Examples¶
function on_view_form_created(item) {
var btn = item.add_view_button('Select', {type: 'primary'});
btn.click(function() {
item.select_records('track');
});
}
function on_view_form_created(item) {
if (!item.view_form.hasClass('modal')) {
var print_btn = item.add_view_button('Print', {image: 'icon-print'}),
email_btn = item.add_view_button('Send email', {image: 'icon-pencil'});
email_btn.click(function() { send_email() });
print_btn.click(function() { print(item) });
}
}