Skip to content

Commit

Permalink
don't select option on ambiguous multi-key radio fields
Browse files Browse the repository at this point in the history
this matches the behaviour of a multi-selection: all matching options are still highlighted, but the radio-option is not set.

also fixes a minor bug with multi-selections not taking `<key> = no` properly into account

closes #8796
  • Loading branch information
tyrasd committed Nov 9, 2021
1 parent 2f9285e commit f3e8852
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/locales/en.min.json

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions modules/ui/fields/radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,12 @@ export function uiFieldRadio(field, context) {


radio.tags = function(tags) {

radios.property('checked', function(d) {
function isOptionChecked(d) {
if (field.key) {
return tags[field.key] === d;
}
return !!(typeof tags[d] === 'string' && tags[d].toLowerCase() !== 'no');
});
}

function isMixed(d) {
if (field.key) {
Expand All @@ -280,13 +279,19 @@ export function uiFieldRadio(field, context) {
return Array.isArray(tags[d]);
}

radios.property('checked', function(d) {
return isOptionChecked(d) &&
(field.key || field.options.filter(isOptionChecked).length === 1);
});

labels
.classed('active', function(d) {
if (field.key) {
return (Array.isArray(tags[field.key]) && tags[field.key].includes(d))
|| tags[field.key] === d;
}
return Array.isArray(tags[d]) || !!(tags[d] && tags[d].toLowerCase() !== 'no');
return Array.isArray(tags[d]) && tags[d].some(v => typeof v === 'string' && v.toLowerCase() !== 'no') ||
!!(typeof tags[d] === 'string' && tags[d].toLowerCase() !== 'no');
})
.classed('mixed', isMixed)
.attr('title', function(d) {
Expand Down

0 comments on commit f3e8852

Please sign in to comment.