[FIX] web: do not allow to edit priority field if readonly

if readonly attribute is given on priority widget then priority widget should
not be clickable and hover effect should be removed so that user can easily
understand that field is readonly.

task-2339680

closes odoo/odoo#59199

X-original-commit: 53dbfc7a65a8eb2f41d6b2373cf628c4800d1f57
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Mohammed Shekha
2020-10-06 08:18:22 +00:00
committed by Aaron Bohy
parent 17b3cd79ab
commit 6dd4aca6b4
2 changed files with 22 additions and 1 deletions
@@ -2312,8 +2312,10 @@ var PriorityWidget = AbstractField.extend({
this.$el.empty();
this.empty_value = this.field.selection[0][0];
this.$el.attr('aria-label', this.string);
const isReadonly = this.record.evalModifiers(this.attrs.modifiers).readonly;
_.each(this.field.selection.slice(1), function (choice, index) {
self.$el.append(self._renderStar('<a href="#">', index_value >= index+1, index+1, choice[1], index_value));
const tag = isReadonly ? '<span>' : '<a href="#">';
self.$el.append(self._renderStar(tag, index_value >= index + 1, index + 1, choice[1], index_value));
});
},
@@ -5915,6 +5915,25 @@ QUnit.module('basic_fields', {
list.destroy();
});
QUnit.test('priority widget with readonly attribute', async function (assert) {
assert.expect(1);
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: `
<form>
<field name="selection" widget="priority" readonly="1"/>
</form>`,
res_id: 2,
});
assert.containsN(form, '.o_field_widget.o_priority span', 2,
"stars of priority widget should rendered with span tag if readonly");
form.destroy();
});
QUnit.module('StateSelection Widget');