When showing a field, set its default value if it has one

This allows universal fields or other standalone fields to have a default value.
This didn't work before becuase default values were only handled by
preset.applyTags() / preset.removeTags().
This commit is contained in:
Bryan Housel
2017-09-11 15:16:02 -04:00
parent 494e247ad1
commit 59f1df902d
2 changed files with 13 additions and 4 deletions

View File

@@ -18,6 +18,7 @@ export function uiField(context, presetField, entity, options) {
var dispatch = d3.dispatch('change'),
field = _.clone(presetField),
show = options.show,
state = '',
tags = {};
@@ -33,8 +34,6 @@ export function uiField(context, presetField, entity, options) {
field.keys = field.keys || [field.key];
field.show = options.show;
function isModified() {
if (!entity) return false;
@@ -176,8 +175,18 @@ export function uiField(context, presetField, entity, options) {
};
field.show = function() {
show = true;
if (field.default && field.key && tags[field.key] !== field.default) {
var t = {};
t[field.key] = field.default;
dispatch.call('change', this, t);
}
};
field.isShown = function() {
return field.show || _.some(field.keys, function(key) { return !!tags[key]; });
return show || _.some(field.keys, function(key) { return !!tags[key]; });
};

View File

@@ -101,7 +101,7 @@ export function uiFormFields(context) {
.minItems(1)
.on('accept', function (d) {
var field = d.field;
field.show = true;
field.show();
render(selection);
if (field.type !== 'semiCombo' && field.type !== 'multiCombo') {
field.focus();