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

defaultValue in Array fields should populate model with SimpleSchema #1008

Closed
Floriferous opened this issue Sep 6, 2021 · 2 comments · Fixed by #1013
Closed

defaultValue in Array fields should populate model with SimpleSchema #1008

Floriferous opened this issue Sep 6, 2021 · 2 comments · Fixed by #1013
Assignees
Labels
Type: Bug Bug reports and their fixes
Milestone

Comments

@Floriferous
Copy link
Contributor

Floriferous commented Sep 6, 2021

When you set a defaultValue in an Array field with SimpleSchema, the initial model doesn't properly reflect it:

const schema = new SimpleSchema({
  list: { type: Array, defaultValue: [{ title: 'Hello world' }] },
  'list.$': Object,
  'list.$.title': String,
})

When a form mounts with this schema, I expect the list field to be already populated with one element, with the title field filled. The model should also contain this data immediately, and not after editing the form first.

Currently, this defaultValue has no effect, and the array is initialized as empty.

@wadamek65
Copy link
Contributor

Hi @Floriferous , thanks for the issue report.

I've checked the behavior that you have described and it seems like there is a problem with logic in the bridge.

JSON Schema bridge seems to return defaultValue right away and returns undefined as a fallback, whereas in SimpleSchema defaultValue is returned as a fallback - in this case the code follows the type === Object path and returns an empty object.

@radekmie Do you know if there is any exact reason for this inconsistency or is this simply an oversight? If it's an oversight, I will create a fix for this.

@wadamek65 wadamek65 self-assigned this Sep 6, 2021
@wadamek65 wadamek65 added the Type: Bug Bug reports and their fixes label Sep 6, 2021
@radekmie
Copy link
Contributor

radekmie commented Sep 6, 2021

@wadamek65 No, that's just an oversight. Feel free to take this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug reports and their fixes
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants