From 554dc77cef4626be5b8edca2f453c3ca3c0830d8 Mon Sep 17 00:00:00 2001 From: Aaron Lidman Date: Wed, 29 Oct 2014 18:24:32 -0400 Subject: [PATCH] Dropdown fixes --- js/id/ui/preset.js | 35 +++++++++++++++-------------------- js/id/ui/preset/address.js | 3 ++- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/js/id/ui/preset.js b/js/id/ui/preset.js index d193e4ee2..afa5c8670 100644 --- a/js/id/ui/preset.js +++ b/js/id/ui/preset.js @@ -164,37 +164,32 @@ iD.ui.preset = function(context) { }; }); - function notShown_placeholder() { - var placeholder = []; - for (var field in notShown) { - placeholder.push(notShown[field].title); - } - return placeholder.slice(0,3).join(', ') + ((placeholder.length > 3) ? '…' : ''); - } - var $more = $form.selectAll('.more-fields') .data((notShown.length > 0) ? [0] : []); - var $input = $more.selectAll('.value') - .data([0]); - $more.enter().append('div') .attr('class', 'more-fields') .append('label') .text('Add additional fields'); + var $input = $more.selectAll('.value') + .data([0]); + $input.enter().append('input') .attr('class', 'value') - .attr('type', 'text') - .attr('placeholder', notShown_placeholder); + .attr('type', 'text'); - $input.call(d3.combobox().data(notShown) - .minItems(1) - .on('accept', function(item) { - show(item); - $input.value('') - .attr('placeholder', notShown_placeholder); - })); + $input.value('') + .attr('placeholder', function() { + var placeholder = []; + for (var field in notShown) { + placeholder.push(notShown[field].title); + } + return placeholder.slice(0,3).join(', ') + ((placeholder.length > 3) ? '…' : ''); + }) + .call(d3.combobox().data(notShown) + .minItems(1) + .on('accept', show)); $more.exit() .remove(); diff --git a/js/id/ui/preset/address.js b/js/id/ui/preset/address.js index 69343e184..cbd42a2f8 100644 --- a/js/id/ui/preset/address.js +++ b/js/id/ui/preset/address.js @@ -203,7 +203,8 @@ iD.ui.preset.address = function(field, context) { }; address.focus = function() { - wrap.selectAll('input').node().focus(); + var node = wrap.selectAll('input').node(); + if (node) node.focus(); }; return d3.rebind(address, event, 'on');