From da5b5fda1da28477041bdb52ad2a0c88a4a99955 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 9 Nov 2021 15:39:10 +0100 Subject: [PATCH] Add getOptionId --- src/style_manager/model/PropertyRadio.js | 11 ++++++++++- src/style_manager/view/PropertyRadioView.js | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/style_manager/model/PropertyRadio.js b/src/style_manager/model/PropertyRadio.js index 5b3099578..a89f4f065 100644 --- a/src/style_manager/model/PropertyRadio.js +++ b/src/style_manager/model/PropertyRadio.js @@ -40,6 +40,15 @@ export default class PropertyRadio extends Property { return this; } + /** + * Get the option id from the option object. + * @param {Object} option Option object + * @returns {String} Option id + */ + getOptionId(option) { + return option.id || option.value; + } + /** * Get option label. * @param {String} id Option id @@ -50,7 +59,7 @@ export default class PropertyRadio extends Property { getOptionLabel(id, opts = {}) { const { locale = true } = opts; const options = this.getOptions(); - const option = options.filter(o => o.id === id || o.value === id)[0] || {}; + const option = options.filter(o => this.getOptionId(o) === id)[0] || {}; const label = option.label || option.name || id; const propId = this.getId(); return ( diff --git a/src/style_manager/view/PropertyRadioView.js b/src/style_manager/view/PropertyRadioView.js index 90961a28c..0bf6bc49c 100644 --- a/src/style_manager/view/PropertyRadioView.js +++ b/src/style_manager/view/PropertyRadioView.js @@ -25,7 +25,7 @@ export default PropertyView.extend({ const cls = opt.className ? `${opt.className} ${pfx}icon ${itemCls}` : ''; - const id = opt.id || opt.value; + const id = model.getOptionId(opt); const elId = `${prop}-${id}-${cid}`; const labelEl = cls ? '' : model.getOptionLabel(id); const titleAttr = opt.title ? `title="${opt.title}"` : '';