mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 17:23:02 +00:00
Don't call formFields.tagsChanged() when presetEditor.tags change
(closes #5690) This change also makes sure to use the latest copy of the entity in field.isAllowed() to ensure the prerequisite field check works and fieldsArr is filtered properly for #5583
This commit is contained in:
@@ -231,38 +231,38 @@ export function uiField(context, presetField, entity, options) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// A shown field has a visible UI, a non-shown field is in the 'Add field' dropdown
|
||||
field.isShown = function() {
|
||||
return _show || isPresent();
|
||||
};
|
||||
|
||||
|
||||
// An allowed field can appear in the UI or in the 'Add field' dropdown.
|
||||
// A non-allowed field is hidden from the user altogether
|
||||
field.isAllowed = function() {
|
||||
if (!entity || isPresent()) return true; // a field with a value should always display
|
||||
|
||||
if (isPresent()) {
|
||||
// always allow a field with a value to display
|
||||
return true;
|
||||
}
|
||||
var latest = context.hasEntity(entity.id); // check the most current copy of the entity
|
||||
if (!latest) return true;
|
||||
|
||||
var prerequisiteTag = field.prerequisiteTag;
|
||||
if (prerequisiteTag && prerequisiteTag.key && field.entityID && context.hasEntity(field.entityID)) {
|
||||
var value = context.entity(field.entityID).tags[prerequisiteTag.key];
|
||||
if (value) {
|
||||
if (prerequisiteTag.valueNot) {
|
||||
return prerequisiteTag.valueNot !== value;
|
||||
}
|
||||
if (prerequisiteTag.value) {
|
||||
return prerequisiteTag.value === value;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
var require = field.prerequisiteTag;
|
||||
if (require && require.key) {
|
||||
var value = latest.tags[require.key];
|
||||
if (!value) return false;
|
||||
|
||||
if (require.valueNot) {
|
||||
return require.valueNot !== value;
|
||||
}
|
||||
if (require.value) {
|
||||
return require.value === value;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
field.focus = function() {
|
||||
if (field.impl) {
|
||||
field.impl.focus();
|
||||
|
||||
@@ -7,24 +7,12 @@ import { utilGetSetValue, utilNoAuto } from '../util';
|
||||
|
||||
export function uiFormFields(context) {
|
||||
var moreCombo = uiCombobox(context, 'more-fields').minItems(1);
|
||||
var _selection = d3_select(null);
|
||||
var _fieldsArr = [];
|
||||
var _state = '';
|
||||
var _klass = '';
|
||||
|
||||
|
||||
function formFields(selection) {
|
||||
_selection = selection
|
||||
.call(render);
|
||||
}
|
||||
|
||||
formFields.tagsChanged = function() {
|
||||
_selection
|
||||
.call(render);
|
||||
};
|
||||
|
||||
|
||||
function render(selection) {
|
||||
var allowedFields = _fieldsArr.filter(function(field) { return field.isAllowed(); });
|
||||
var shown = allowedFields.filter(function(field) { return field.isShown(); });
|
||||
var notShown = allowedFields.filter(function(field) { return !field.isShown(); });
|
||||
@@ -111,7 +99,7 @@ export function uiFormFields(context) {
|
||||
.on('accept', function (d) {
|
||||
var field = d.field;
|
||||
field.show();
|
||||
render(selection);
|
||||
selection.call(formFields); // rerender
|
||||
if (field.type !== 'semiCombo' && field.type !== 'multiCombo') {
|
||||
field.focus();
|
||||
}
|
||||
|
||||
@@ -121,7 +121,6 @@ export function uiPresetEditor(context) {
|
||||
presetEditor.tags = function(val) {
|
||||
if (!arguments.length) return _tags;
|
||||
_tags = val;
|
||||
formFields.tagsChanged();
|
||||
// Don't reset _fieldsArr here.
|
||||
return presetEditor;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user