From 6dc02d7f22a4aede8a4052d95b02b363233af83b Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Mon, 27 Jan 2020 16:35:15 -0500 Subject: [PATCH] Properly hide the input field on semicombos when there aren't enough characters remaining to add another value (re: #6817) --- modules/ui/fields/combo.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index 5de03db57..e9cc277b1 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -432,9 +432,18 @@ export function uiFieldCombo(field, context) { }; }); + var currLength = arr.join(';').length; + // limit the input length to the remaining available characters - maxLength = services.osm.maxCharsForTagValue() - (tags[field.key] || '').length; + maxLength = services.osm.maxCharsForTagValue() - currLength; + + if (currLength > 0) { + // account for the separator if a new value will be appended to existing + maxLength -= 1; + } } + // a negative maxlength doesn't make sense + maxLength = Math.max(0, maxLength); // Exclude existing multikeys from combo options.. var available = objectDifference(_comboData, _multiData); @@ -443,8 +452,9 @@ export function uiFieldCombo(field, context) { // Hide 'Add' button if this field uses fixed set of // translateable optstrings and they're all currently used, // or if the field is already at its character limit - container.selectAll('.combobox-input, .combobox-caret') - .classed('hide', (optstrings && !available.length) || !maxLength); + var hideAdd = (optstrings && !available.length) || maxLength <= 0; + container.selectAll('.chiplist .input-wrap') + .style('display', hideAdd ? 'none' : null); // Render chips