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

[AdminUI] defaultValue as function not working on Calendar Day #2370

Closed
maximelebreton opened this issue Feb 15, 2020 · 4 comments
Closed

[AdminUI] defaultValue as function not working on Calendar Day #2370

maximelebreton opened this issue Feb 15, 2020 · 4 comments

Comments

@maximelebreton
Copy link

maximelebreton commented Feb 15, 2020

Hey there,

I wanted to put the current day as default value on the CalendarDay field.

So I read the fields config documentation:
image

And then CalendarDay config documentation

I tried to do this, but it doesn't work:

fields: {
    date: {
      type: CalendarDay,
      defaultValue: () => Date.now().toISOString() // doesn't work

So to be sure, I tried this, and it works:

fields: {
    date: {
      type: CalendarDay,
      defaultValue: "2020-01-01" // works
    }

So I tried this, and it doesn't work...

fields: {
    date: {
      type: CalendarDay,
      defaultValue: () => "2020-01-01" // doesn't work
    }

So the defaultValue prop as function doesn't work...

Maybe it's related to all fields, I haven't tested it?

Personal thought:
Please switch to Typescript, we shouldn't meet anymore this kind of stuff in 2020 :)

@2xAA
Copy link

2xAA commented Feb 17, 2020

This also seems to be the case with the DateTime type.

My schema:

fields: {
  createdAt: {
    type: DateTime,
    defaultValue: () => new Date().toISOString()
  }
}

This does seem to be an AdminUI issue only. Using the GraphQL playground this works fine.

@reubano
Copy link

reubano commented Feb 23, 2020

dupe #2043

@MadeByMike
Copy link
Contributor

Yes, this is a duplicate and I've just updated the documentation so that this doesn't happen again. @maximelebreton I'm sorry for the confusion please for why this must be a string: #2043

@Vultraz
Copy link
Contributor

Vultraz commented Mar 23, 2020

Actually, after #2347 the function default should work as long as isRequired is false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants