i need to Change odoo 10 default save button name of forms for particular form
i need to change the button background for save button depending upon form name (mine is a custom module and form)
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
i need to Change odoo 10 default save button name of forms for particular form
i need to change the button background for save button depending upon form name (mine is a custom module and form)
You can override the render_buttons function
odoo.define('my_module.CustomSaveButtonName', function (require) {
"use strict";
var FormView = require('web.FormView');
var core = require('web.core');
var QWeb = core.qweb;
var ajax = require('web.ajax');
ajax.loadXML('/my_module/static/src/xml/button_save.xml', QWeb);
FormView.include({
render_buttons: function($node) {
this.$buttons = $('<div/>');
var $footer = this.$('footer');
if (this.options.action_buttons !== false || this.options.footer_to_buttons && $footer.children().length === 0) {
if(this.model == 'my.custom.model'){
this.$buttons.append(QWeb.render("FormView.buttons", {'widget': this, 'custom_save_name': 'MyName'}));
}else{
this.$buttons.append(QWeb.render("FormView.buttons", {'widget': this}));
}
}
if (this.options.footer_to_buttons) {
$footer.appendTo(this.$buttons);
}
// Show or hide the buttons according to the view mode
this.toggle_buttons();
this.$buttons.on('click', '.o_form_button_create', this.on_button_create);
this.$buttons.on('click', '.o_form_button_edit', this.on_button_edit);
this.$buttons.on('click', '.o_form_button_save', this.on_button_save);
this.$buttons.on('click', '.o_form_button_cancel', this.on_button_cancel);
this.$buttons.appendTo($node);
},
});
});
Then in a template located in /my_module/static/src/xml/button_save.xml
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-extend="FormView.buttons">
<t t-jquery="button.o_form_button_save" t-operation="replace">
<button type="button" class="btn btn-primary btn-sm o_form_button_save" accesskey="s">
<span t-if="custom_save_name" t-esc="custom_save_name"/>
<span t-else="">Save</span>
</button>
</t>
</t>
</templates>
For the background color, use the same logic. The this.dataset variable contains useful information
like the context dict.
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up