Merge lp:~openerp-dev/openobject-client-web/6.0-opw-381794-msh into lp:openobject-client-web

Proposed by Mohammed Shekha(Open ERP)
Status: Merged
Approved by: Xavier ALT
Approved revision: 4759
Merged at revision: 4860
Proposed branch: lp:~openerp-dev/openobject-client-web/6.0-opw-381794-msh
Merge into: lp:openobject-client-web
Diff against target: 49 lines (+6/-1)
1 file modified
addons/openerp/static/javascript/m2o.js (+6/-1)
To merge this branch: bzr merge lp:~openerp-dev/openobject-client-web/6.0-opw-381794-msh
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+90074@code.launchpad.net

Description of the change

Hello,

Fixed the issue of initial onchange trigger from m2o field.

Demo :- HR -> Expenses -> create new expense you will see onchange is not fired from Employee field, employee field have onchange which sets department.

Reason :- Here in m2o.js we have removed attr callback from visible field (there is always one hidden field for each visible field), to avoid calling onChange two times one from hidden field and one from visible field(According to Revision no. 4618) but due to this revision initial_onchange has been stop working because we have called initial_onchange on form ready, when form have been ready at that time m2o.js already removed the callback attr from visible field so when initial_onchange is called it will not call the on_change of employee field, initial_onchange is called only for visible fields not for hidden fields, so due to removal of callback attr from visible employee m2o onChange is not called.

If we remove this revision then initial onchange will be called but when user change that field at that time onchange will be called two times because we have bind all m2o field with on_change method of m2o.js, and one another on_change is called for callback on visible field, so we need to remove callback from visible field but we will remove after form load so when form is loaded at that time one time initial_onchange is called and after that we will remove callback from visible field so now when user change the field at that time only binded field onChange called.

So Changed the code and removed the callback after form is loaded.

Thanks.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/openerp/static/javascript/m2o.js'
2--- addons/openerp/static/javascript/m2o.js 2011-08-04 14:07:40 +0000
3+++ addons/openerp/static/javascript/m2o.js 2012-01-25 11:01:42 +0000
4@@ -72,7 +72,7 @@
5 keyup: jQuery.proxy(this, 'on_keyup'),
6 focus: jQuery.proxy(this, 'gotFocus'),
7 blur: jQuery.proxy(this, 'lostFocus')
8- }).removeAttr('callback');
9+ });
10
11 this.lastTextResult = this.text.value;
12
13@@ -96,10 +96,12 @@
14 };
15
16 ManyToOne.prototype.gotFocus = function(evt) {
17+ jQuery(this.text).removeAttr('callback');
18 this.hasFocus = true;
19 };
20
21 ManyToOne.prototype.lostFocus = function() {
22+ jQuery(this.text).removeAttr('callback');
23 this.hasFocus = false;
24 if(this.selectedResult || this.lastKey == 9) {
25 this.lastKey = null;
26@@ -233,6 +235,7 @@
27 };
28
29 ManyToOne.prototype.on_keyup = function() {
30+ jQuery(this.text).removeAttr('callback');
31 // Stop processing if a special key has been pressed. Or if the last search requested the same string
32 if(this.specialKeyPressed || (this.text.value == this.lastSearch)) return false;
33
34@@ -266,6 +269,7 @@
35 };
36
37 ManyToOne.prototype.on_keydown = function(evt) {
38+ jQuery(this.text).removeAttr('callback');
39 this.lastKey = evt.which;
40 // Used to stop processing of further key functions
41 this.specialKeyPressed = false;
42@@ -358,6 +362,7 @@
43 };
44
45 ManyToOne.prototype.on_keypress = function(evt) {
46+ jQuery(this.text).removeAttr('callback');
47 // We use 'keyCode' instead if 'which' because keypress is only triggered on 'character' keys except in firefox.
48 if (evt.keyCode == 9 || evt.ctrlKey) {
49 return true;