[FIX] Fixed form's fields autofocus
bzr revid: fme@openerp.com-20120802124909-w4li8dt6y0kktnfh
This commit is contained in:
commit
9c31ba65d9
|
@ -79,6 +79,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
|||
_.defaults(this.options, {
|
||||
"not_interactible_on_create": false,
|
||||
"initial_mode": "view",
|
||||
"disable_autofocus": false,
|
||||
});
|
||||
this.is_initialized = $.Deferred();
|
||||
this.mutating_mutex = new $.Mutex();
|
||||
|
@ -269,9 +270,11 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
|||
if (this.$pager) {
|
||||
this.$pager.show();
|
||||
}
|
||||
this.$element.show().css({
|
||||
opacity: '0',
|
||||
filter: 'alpha(opacity = 0)'
|
||||
});
|
||||
this.$element.add(this.$buttons).removeClass('oe_form_dirty');
|
||||
this.$element.css('visibility', 'visible');
|
||||
this._super();
|
||||
|
||||
var shown = this.has_been_loaded;
|
||||
if (options.reload !== false) {
|
||||
|
@ -291,6 +294,10 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
|||
if (options.editable) {
|
||||
self.to_edit_mode();
|
||||
}
|
||||
self.$element.css({
|
||||
opacity: '1',
|
||||
filter: 'alpha(opacity = 100)'
|
||||
});
|
||||
});
|
||||
},
|
||||
do_hide: function () {
|
||||
|
@ -350,6 +357,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
|||
self.do_push_state({id:record.id});
|
||||
}
|
||||
self.$element.add(self.$buttons).removeClass('oe_form_dirty');
|
||||
self.autofocus();
|
||||
});
|
||||
},
|
||||
/**
|
||||
|
@ -649,15 +657,21 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
|||
_.each(this.fields,function(field){
|
||||
field.set({"force_readonly": false});
|
||||
});
|
||||
var fields_order = self.fields_order.slice(0);
|
||||
if (self.default_focus_field) {
|
||||
fields_order.unshift(self.default_focus_field.name);
|
||||
this.autofocus();
|
||||
}
|
||||
},
|
||||
autofocus: function() {
|
||||
if (this.get("actual_mode") !== "view" && !this.options.disable_autofocus) {
|
||||
var fields_order = this.fields_order.slice(0);
|
||||
if (this.default_focus_field) {
|
||||
fields_order.unshift(this.default_focus_field.name);
|
||||
}
|
||||
for (var i = 0; i < fields_order.length; i += 1) {
|
||||
var field = self.fields[fields_order[i]];
|
||||
var field = this.fields[fields_order[i]];
|
||||
if (!field.get('effective_invisible') && !field.get('effective_readonly')) {
|
||||
field.focus();
|
||||
break;
|
||||
if (field.focus() !== false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1962,14 +1976,7 @@ instance.web.form.AbstractField = instance.web.form.FormWidget.extend(instance.w
|
|||
}
|
||||
},
|
||||
focus: function() {
|
||||
},
|
||||
/**
|
||||
* Utility method to focus an element, but only after a small amount of time.
|
||||
*/
|
||||
delay_focus: function($elem) {
|
||||
setTimeout(function() {
|
||||
$elem[0].focus();
|
||||
}, 50);
|
||||
return false;
|
||||
},
|
||||
/**
|
||||
* Utility method to get the widget options defined in the field xml description.
|
||||
|
@ -2068,7 +2075,7 @@ instance.web.form.FieldChar = instance.web.form.AbstractField.extend(instance.we
|
|||
return this.get('value') === '' || this._super();
|
||||
},
|
||||
focus: function() {
|
||||
this.$element.find('input:first')[0].focus();
|
||||
this.$element.find('input:first').focus();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2288,8 +2295,9 @@ instance.web.form.FieldDatetime = instance.web.form.AbstractField.extend(instanc
|
|||
return this.get('value') === '' || this._super();
|
||||
},
|
||||
focus: function() {
|
||||
if (this.datewidget && this.datewidget.$input)
|
||||
this.delay_focus(this.datewidget.$input);
|
||||
if (this.datewidget && this.datewidget.$input) {
|
||||
this.datewidget.$input.focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2344,7 +2352,7 @@ instance.web.form.FieldText = instance.web.form.AbstractField.extend(instance.we
|
|||
return this.get('value') === '' || this._super();
|
||||
},
|
||||
focus: function($element) {
|
||||
this.delay_focus(this.$textarea);
|
||||
this.$textarea.focus();
|
||||
},
|
||||
do_resize: function(max_height) {
|
||||
max_height = parseInt(max_height, 10);
|
||||
|
@ -2437,7 +2445,7 @@ instance.web.form.FieldBoolean = instance.web.form.AbstractField.extend({
|
|||
this.$checkbox[0].checked = value_;
|
||||
},
|
||||
focus: function() {
|
||||
this.delay_focus(this.$checkbox);
|
||||
this.$checkbox.focus();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2529,7 +2537,7 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(instan
|
|||
return !! value_;
|
||||
},
|
||||
focus: function() {
|
||||
this.delay_focus(this.$element.find('select:first'));
|
||||
this.$element.find('select:first').focus();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2921,7 +2929,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
|
|||
return ! this.get("value");
|
||||
},
|
||||
focus: function () {
|
||||
this.delay_focus(this.$input);
|
||||
this.$input.focus();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -4692,9 +4700,6 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({
|
|||
elem.css("color", color);
|
||||
}
|
||||
},
|
||||
focus: function() {
|
||||
return false;
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
|
@ -602,6 +602,7 @@ openerp.web.list_editable = function (instance) {
|
|||
this.form = new (this.options.formView)(
|
||||
this, this.delegate.dataset, false, {
|
||||
initial_mode: 'edit',
|
||||
disable_autofocus: true,
|
||||
$buttons: $(),
|
||||
$pager: $()
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue