From dd3dd3e066f293cc2ac5a586cc48576c71efdec4 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 14 Dec 2021 15:20:23 +0100 Subject: [PATCH] Add getOption to radio property --- src/style_manager/model/PropertyRadio.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/style_manager/model/PropertyRadio.js b/src/style_manager/model/PropertyRadio.js index be7aed166..d3fe7886d 100644 --- a/src/style_manager/model/PropertyRadio.js +++ b/src/style_manager/model/PropertyRadio.js @@ -5,7 +5,7 @@ export default class PropertyRadio extends Property { return { ...Property.prototype.defaults, options: [], // Array of options, eg. [{ id: '100', label: 'Set 100' }] - full: 1 + full: 1, }; } @@ -19,6 +19,15 @@ export default class PropertyRadio extends Property { return (options && options.length ? options : list) || []; } + /** + * Get current selected option. + * @returns {Object | null} + */ + getOption() { + const id = this.getValue(); + return this.getOptions().filter(o => this.getOptionId(o) === id)[0] || null; + } + /** * Update options. * @param {Array} value Array of options, eg. `[{ id: 'val-1', label: 'Value 1' }]` @@ -62,9 +71,7 @@ export default class PropertyRadio extends Property { const option = options.filter(o => this.getOptionId(o) === id)[0] || {}; const label = option.label || option.name || id; const propId = this.getId(); - return ( - (locale && this.em?.t(`styleManager.options.${propId}.${id}`)) || label - ); + return (locale && this.em?.t(`styleManager.options.${propId}.${id}`)) || label; } initialize(...args) {