Skip to content

Commit

Permalink
fix: field props fallback
Browse files Browse the repository at this point in the history
505
  • Loading branch information
foxhound87 committed Jun 28, 2019
1 parent 2182ba3 commit 20139a9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class Options {

@observable options = {
uniqueId,
fallback: true,
defaultGenericError: null,
submitThrowsError: true,
showErrorsOnInit: false,
Expand Down Expand Up @@ -33,7 +34,6 @@ export default class Options {
leading: false,
trailing: true,
},
fallbackFields: true
};

get(key = null, field = null) {
Expand Down
8 changes: 4 additions & 4 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const reduceValuesToUnifiedFields = values =>
/*
Fallback Unified Props to Sepated Mode
*/
const handleFieldsPropsFallback = (fields, initial, fallbackFields) => {
const handleFieldsPropsFallback = (fields, initial, fallback) => {
if (!_.has(initial, 'values')) return fields;
// if the 'values' object is passed in constructor
// then update the fields definitions
Expand All @@ -185,7 +185,7 @@ const handleFieldsPropsFallback = (fields, initial, fallbackFields) => {
}
return _.merge(fields, _.transform(values, (result, v, k) => {
if (_.isArray(fields[k])) result[k] = v
if (!(k in fields) && fallbackFields) result[k] = v
if (!(k in fields) && fallback) result[k] = v
}, {}));
};

Expand All @@ -204,14 +204,14 @@ const mergeSchemaDefaults = (fields, validator) => {
return fields;
};

const prepareFieldsData = (initial, strictProps = true, fallbackFields = true) => {
const prepareFieldsData = (initial, strictProps = true, fallback = true) => {
let fields = _.merge(
handleFieldsArrayOfStrings(initial.fields, false),
handleFieldsArrayOfStrings(initial.struct, false),
);

fields = handleFieldsArrayOfObjects(fields);
fields = handleFieldsPropsFallback(fields, initial, fallbackFields);
fields = handleFieldsPropsFallback(fields, initial, fallback);
fields = handleFieldsNested(fields, strictProps);

return fields;
Expand Down
3 changes: 2 additions & 1 deletion src/shared/Initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import parser from '../parser';
export default {

initFields(initial, update) {
const fallback = this.state.options.get('fallback');
const $path = key => _.trimStart([this.path, key].join('.'), '.');

let fields;
fields = parser.prepareFieldsData(initial, this.state.strict, this.state.options.get('fallbackFields'));
fields = parser.prepareFieldsData(initial, this.state.strict, fallback);
fields = parser.mergeSchemaDefaults(fields, this.validator);

// create fields
Expand Down

0 comments on commit 20139a9

Please sign in to comment.