Skip to content

Commit

Permalink
Fixed SimpleSchema2Bridge defaultValue handling (closes #130).
Browse files Browse the repository at this point in the history
  • Loading branch information
radekmie committed Nov 19, 2016
1 parent 4f10ed0 commit 839b317
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Next
- **Fixed:** Handling of `defaultValue` in `SimpleSchema2Bridge`. [\#130](https://github.com/vazco/uniforms/issues/130)

<br>

## [v1.6.0-beta.2](https://github.com/vazco/uniforms/releases/tag/v1.6.0-beta.2)
- **Fixed:** GraphQL conditional import.

Expand Down Expand Up @@ -75,7 +80,7 @@
<br>

## [v1.1.2](https://github.com/vazco/uniforms/releases/tag/v1.1.2)
- **Fixed:** Enabled SimpleSchema2Bridge. [\#107](https://github.com/vazco/uniforms/issues/107)
- **Fixed:** Enabled `SimpleSchema2Bridge`. [\#107](https://github.com/vazco/uniforms/issues/107)

<br>

Expand Down
15 changes: 14 additions & 1 deletion packages/uniforms/src/bridges/SimpleSchema2Bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,20 @@ export default class SimpleSchema2Bridge extends Bridge {

invariant(definition, 'Field not found in schema: "%s"', name);

return {...definition, ...definition.type[0]};
const merged = {
...definition,
...definition.type[0]
};

// aldeed/node-simple-schema#27
if (merged.autoValue && (
merged.autoValue.name === 'defaultAutoValueFunction' ||
merged.autoValue.toString().indexOf('$setOnInsert:') !== -1 // FIXME: Hack.
)) {
merged.defaultValue = merged.autoValue.call({operator: null});
}

return merged;
}

getInitialValue (name, props = {}) {
Expand Down

0 comments on commit 839b317

Please sign in to comment.