Merge branch 'master' into validation

This commit is contained in:
Quincy Morgan
2018-12-19 12:14:32 -05:00
18 changed files with 413 additions and 16 deletions
+34 -4
View File
@@ -48,10 +48,12 @@ export function uiField(context, presetField, entity, options) {
dispatch.call('change', field, t, onInput);
});
// if this field cares about the entity, pass it along
if (entity && field.impl.entity) {
if (entity) {
field.entityID = entity.id;
field.impl.entity(entity);
// if this field cares about the entity, pass it along
if (field.impl.entity) {
field.impl.entity(entity);
}
}
}
@@ -229,11 +231,39 @@ 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 (isPresent()) {
// always allow a field with a value to display
return true;
}
var prerequisiteTag = field.prerequisiteTag;
if (prerequisiteTag && field.entityID) {
if (prerequisiteTag.key) {
var value = context.graph().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;
}
}
}
return true;
};
field.focus = function() {
if (field.impl) {
+11 -2
View File
@@ -16,9 +16,18 @@ export function uiFormFields(context) {
}
formFields.tagsChanged = function() {};
function render(selection, klass) {
var shown = _fieldsArr.filter(function(field) { return field.isShown(); });
var notShown = _fieldsArr.filter(function(field) { return !field.isShown(); });
formFields.tagsChanged = function() {
render(selection, klass);
};
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(); });
var container = selection.selectAll('.form-fields-container')
.data([0]);
+1
View File
@@ -120,6 +120,7 @@ export function uiPresetEditor(context) {
presetEditor.tags = function(val) {
if (!arguments.length) return _tags;
_tags = val;
formFields.tagsChanged();
// Don't reset _fieldsArr here.
return presetEditor;
};