Skip to content

Commit 3cc077e

Browse files
committed
fix handling of fields attribute
1 parent f93eb7b commit 3cc077e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

autoform-helpers.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Template.registerHelper("afFieldNames", function autoFormFieldNames(options) {
128128
}
129129

130130
// Get the list of fields we want included
131-
var fieldList = options.fields;
131+
var fieldList = options.fields, usedAncestorFieldList = false;
132132
if (fieldList) {
133133
fieldList = AutoForm.Utility.stringToArray(fieldList, 'AutoForm: fields attribute must be an array or a string containing a comma-delimited list of fields');
134134
}
@@ -139,8 +139,9 @@ Template.registerHelper("afFieldNames", function autoFormFieldNames(options) {
139139

140140
// Use the ancestor field list as backup, unless there is
141141
// a name and that name is listed in the ancestor field list
142-
if (!fieldList && (!name || !_.contains(ancestorFieldList, name))) {
142+
if (!fieldList) {
143143
fieldList = ancestorFieldList;
144+
usedAncestorFieldList = true;
144145
}
145146
}
146147

@@ -149,7 +150,7 @@ Template.registerHelper("afFieldNames", function autoFormFieldNames(options) {
149150
// Take only those fields in the fieldList that are descendants of the `name` field
150151
if (name) {
151152
// Replace generic name with real name. We assume that field names
152-
// with $ apply to all array items. Field list will not have the
153+
// with $ apply to all array items. Field list will now have the
153154
// correct array field item number instead of $.
154155
if (genericName !== name) {
155156
fieldList = _.map(fieldList, function (field) {
@@ -194,7 +195,7 @@ Template.registerHelper("afFieldNames", function autoFormFieldNames(options) {
194195
});
195196
}
196197

197-
if (!fieldList) {
198+
if (!fieldList || (fieldList.length === 0 && usedAncestorFieldList)) {
198199
// Get list of field names that are descendants of this field's name.
199200
// If name/genericName is undefined, this will return top-level
200201
// schema keys.

0 commit comments

Comments
 (0)