Skip to content

Commit

Permalink
Fix DynamicForm ignoring default value for checkboxes (#3487)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldutra authored and arikfr committed Feb 26, 2019
1 parent 60cd881 commit 138c55c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions client/app/components/dynamic-form/dynamicFormHelper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { each, includes } from 'lodash';
import { each, includes, isUndefined } from 'lodash';

function orderedInputs(properties, order, targetOptions) {
const inputs = new Array(order.length);
Expand Down Expand Up @@ -46,8 +46,21 @@ function normalizeSchema(configurationSchema) {
configurationSchema.order = configurationSchema.order || [];
}

function getFields(configurationSchema, target) {
function setDefaultValueForCheckboxes(configurationSchema, options = {}) {
if (Object.keys(options).length === 0) {
const properties = configurationSchema.properties;
Object.keys(properties).forEach((property) => {
if (!isUndefined(properties[property].default) && properties[property].type === 'checkbox') {
options[property] = properties[property].default;
}
});
}
}

function getFields(configurationSchema, target = {}) {
normalizeSchema(configurationSchema);
setDefaultValueForCheckboxes(configurationSchema, target.options);

const inputs = [
{
name: 'name',
Expand Down

0 comments on commit 138c55c

Please sign in to comment.