[FIX] web: fix missing idForLabel on some widgets

Widgets which manipulates their dom in _renderEdit were left out
from the previous implementation since this processing was done
only once when the widget is rendered the first time. If the
widget regenerates a new input upon reset for example, then it
would lack the idForLabel.
This commit is contained in:
David Monjoie
2017-05-02 15:24:54 +02:00
parent 4e4c89969c
commit e02cee4ea6
2 changed files with 51 additions and 3 deletions
@@ -52,6 +52,23 @@ var FormRenderer = BasicRenderer.extend({
});
return fieldNames;
},
/**
* @see BasicRenderer.confirmChange
*
* We need to reapply the idForLabel postprocessing since some widgets may
* have recomputed their dom entirely.
*
* @override
*/
confirmChange: function (state, id, fields, e) {
var self = this;
return this._super.apply(this, arguments).then(function (resetWidgets) {
_.each(resetWidgets, function (widget) {
self._setIDForLabel(widget, self.idsForLabels[widget.name]);
});
return resetWidgets
});
},
/**
* returns the active tab pages for each notebook
*
@@ -256,7 +273,7 @@ var FormRenderer = BasicRenderer.extend({
}, modifiersOptions || {});
var widget = this._super(node, record, options, modifiersOptions);
widget.getFocusableElement().attr('id', this._getIDForLabel(node.attrs.name));
this._setIDForLabel(widget, this._getIDForLabel(node.attrs.name));
widget.$el.addClass(FIELD_CLASSES[record.fields[node.attrs.name].type]);
this._addFieldClassNames(widget);
@@ -730,6 +747,16 @@ var FormRenderer = BasicRenderer.extend({
focusWidget.activate(true);
}
},
/**
* Sets id attribute of given widget to idForLabel
*
* @private
* @param {AbstractField} widget
* @param {idForLabel} string
*/
_setIDForLabel: function (widget, idForLabel) {
widget.getFocusableElement().attr('id', idForLabel);
},
//--------------------------------------------------------------------------
// Handlers
@@ -120,13 +120,13 @@ QUnit.module('basic_fields', {
QUnit.module('FieldBoolean');
QUnit.test('boolean field in form view', function (assert) {
assert.expect(7);
assert.expect(11);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="bar"/></form>',
arch: '<form><label for="bar" string="Awesome checkbox"/><field name="bar"/></form>',
res_id: 1,
});
@@ -152,6 +152,27 @@ QUnit.module('basic_fields', {
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('.o_field_boolean input:checked').length, 0,
"checkbox should still be unchecked");
// check the checkbox
form.$('.o_field_boolean input').click();
assert.strictEqual(form.$('.o_field_boolean input:checked').length, 1,
"checkbox should now be checked");
// uncheck it back
form.$('.o_field_boolean input').click();
assert.strictEqual(form.$('.o_field_boolean input:checked').length, 0,
"checkbox should now be unchecked");
// check the checkbox by clicking on label
form.$('label').click();
assert.strictEqual(form.$('.o_field_boolean input:checked').length, 1,
"checkbox should now be checked");
// uncheck it back
form.$('label').click();
assert.strictEqual(form.$('.o_field_boolean input:checked').length, 0,
"checkbox should now be unchecked");
// check the checkbox by hitting the "enter" key after focusing it
form.$('.o_field_boolean input')
.trigger("focusin")