From 9aceb8f725eaafa8482de39b8260bf7e5041cfe6 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 11 Dec 2018 19:01:23 -0500 Subject: [PATCH] Fix lazy instantiation of the fields They are shown either if `_show=true` or `isPresent()` --- modules/ui/field.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/ui/field.js b/modules/ui/field.js index 37a436e47..27649d105 100644 --- a/modules/ui/field.js +++ b/modules/ui/field.js @@ -40,7 +40,8 @@ export function uiField(context, presetField, entity, options) { createField(); } - // field implementation + // Creates the field.. This is done lazily, + // once we know that the field will be shown. function createField() { field.impl = uiFields[field.type](field, context) .on('change', function(t, onInput) { @@ -66,7 +67,7 @@ export function uiField(context, presetField, entity, options) { function isPresent() { return _some(field.keys, function(key) { - return _tags[key]; + return _tags[key] !== undefined; }); } @@ -154,7 +155,9 @@ export function uiField(context, presetField, entity, options) { .classed('modified', isModified()) .classed('present', isPresent()) .each(function(d) { - if (!d.impl) return; // field is not yet shown + if (!d.impl) { + createField(); + } var reference, help; @@ -228,12 +231,14 @@ export function uiField(context, presetField, entity, options) { field.isShown = function() { - return _show || _some(field.keys, function(key) { return !!_tags[key]; }); + return _show || isPresent(); }; field.focus = function() { - field.impl.focus(); + if (field.impl) { + field.impl.focus(); + } };