From b37a08d4133cd6c228b59832435ac15a5e42d211 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 24 Jun 2015 10:49:32 -0400 Subject: [PATCH] [fix] in form header refresh, if doc is switched, reset this.current_status, so that correct primary/secondary buttons are rendered --- frappe/public/js/legacy/form.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/frappe/public/js/legacy/form.js b/frappe/public/js/legacy/form.js index b9f96bfaab..b337e99110 100644 --- a/frappe/public/js/legacy/form.js +++ b/frappe/public/js/legacy/form.js @@ -298,7 +298,7 @@ _f.Frm.prototype.setup_meta = function(doctype) { if(this.meta.istable) { this.meta.in_dialog = 1 } } -_f.Frm.prototype.refresh_header = function() { +_f.Frm.prototype.refresh_header = function(is_a_different_doc) { // set title // main title if(!this.meta.in_dialog || this.in_form) { @@ -310,6 +310,10 @@ _f.Frm.prototype.refresh_header = function() { // show / hide buttons if(this.toolbar) { + if (is_a_different_doc) { + this.toolbar.current_status = undefined; + } + this.toolbar.refresh(); } @@ -341,8 +345,10 @@ _f.Frm.prototype.check_doc_perm = function() { } _f.Frm.prototype.refresh = function(docname) { - // record switch + var is_a_different_doc = docname ? true : false; + if(docname) { + // record switch if(this.docname != docname && (!this.meta.in_dialog || this.in_form) && !this.meta.istable) { scroll(0, 0); @@ -388,7 +394,7 @@ _f.Frm.prototype.refresh = function(docname) { cur_frm.cscript.is_onload = true; this.setnewdoc(); } else { - this.render_form(); + this.render_form(is_a_different_doc); } // if print format is shown, refresh the format @@ -398,7 +404,7 @@ _f.Frm.prototype.refresh = function(docname) { } } -_f.Frm.prototype.render_form = function() { +_f.Frm.prototype.render_form = function(is_a_different_doc) { if(!this.meta.istable) { this.layout.doc = this.doc; this.layout.attach_doc_and_docfields() @@ -410,7 +416,7 @@ _f.Frm.prototype.render_form = function() { // header must be refreshed before client methods // because add_custom_button - this.refresh_header(); + this.refresh_header(is_a_different_doc); // call trigger this.script_manager.trigger("refresh"); @@ -438,7 +444,7 @@ _f.Frm.prototype.render_form = function() { } } else { - this.refresh_header(); + this.refresh_header(is_a_different_doc); } $(cur_frm.wrapper).trigger('render_complete');