From f7461fc49bbdcbc78ddff89016c88be1012d307b Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Sat, 16 Mar 2013 00:11:25 -0400 Subject: [PATCH] radio preset input now works for the same key if a key is specified for the field, then all options are considered values for that key. Otherwise options are keys, and the selected value is yes. --- js/id/ui/preset/radio.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/js/id/ui/preset/radio.js b/js/id/ui/preset/radio.js index 1b645bf36..9e8eb97ac 100644 --- a/js/id/ui/preset/radio.js +++ b/js/id/ui/preset/radio.js @@ -12,7 +12,7 @@ iD.ui.preset.radio = function(field) { .data(field.options) .enter() .append('button') - .text(function(d) { return field.t('options.' + d, {default: d}); }) + .text(function(d) { return field.t('options.' + d, { 'default': d }); }) .on('click', function() { buttons.classed('active', false); d3.select(this).classed('active', true); @@ -30,15 +30,25 @@ iD.ui.preset.radio = function(field) { function change() { var t = {}; + if (field.key) t[field.key] = null; buttons.each(function(d) { - t[d] = d3.select(this).classed('active') ? 'yes' : ''; + var active = d3.select(this).classed('active'); + if (field.key) { + if (active) t[field.key] = d; + } else { + t[d] = active ? 'yes' : ''; + } }); event.change(t); } radio.tags = function(tags) { buttons.classed('active', function(d) { - return tags[d] && tags[d] !== 'no'; + if (field.key) { + return tags[field.key] === d; + } else { + return tags[d] && tags[d] !== 'no'; + } }); };