Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small patch to resolve issue with fields being shown twice when using groups #1682

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion components/quickForm/quickForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,68 @@ Template.quickForm.helpers({
grouplessFields: grouplessFieldContext
}
}
})
});

/* Private Functions */

/**
* Takes a schema object and returns a sorted array of field group names for it
*
* @param {Object} schemaObj Like from mySimpleSchema.schema()
* @returns {String[]} Array of field group names
*/
function getSortedFieldGroupNames(schemaObj) {
var names = _.map(schemaObj, function (field) {
return field.autoform && field.autoform.group;
});

// Remove undefined
names = _.compact(names);

// Remove duplicate names
names = _.unique(names);

return names.sort();
}

/**
* Returns the schema field names that belong in the group.
*
* @param {String} groupName The group name
* @param {Object} schemaObj Like from mySimpleSchema.schema()
* @returns {String[]} Array of field names (schema keys)
*/
function getFieldsForGroup(groupName, schemaObj) {
var fields = _.map(schemaObj, function (field, fieldName) {
return (fieldName.slice(-2) !== '.$') &&
field.autoform &&
field.autoform.group === groupName &&
fieldName;
});

// Remove undefined
fields = _.compact(fields);

return fields;
}

/**
* Returns the schema field names that don't belong to a group
*
* @param {Object} schemaObj Like from mySimpleSchema.schema()
* @returns {String[]} Array of field names (schema keys)
*/
function getFieldsWithNoGroup(schemaObj) {
var fields = _.map(schemaObj, function (field, fieldName) {
let parent = schemaObj[fieldName.substr(0, fieldName.indexOf('.'))];
return (fieldName.slice(-2) !== '.$') &&
(!field.autoform || !field.autoform.group) &&
(!parent || !parent.autoform || !parent.autoform.group) &&
fieldName;
});

// Remove undefined
fields = _.compact(fields);

return fields;
}
Loading