defaultValue function values possibly broken
See original GitHub issueBug report
Describe the bug
Ok, so the docs say fields can take a defaultValue
key as a string or function. Strings work fine, but I can’t seem to get functions to do anything at all.
I notice they aren’t passed to the Admin UI, so it makes sense they wouldn’t resolve and display when creating an item, but even if you simply save a field with no value the defaultValue
function is never called.
Testing using this config in the TODO demo:
keystone.createList('Todo', {
schemaDoc: 'A list of things which need to be done',
fields: {
name: {
type: Text,
schemaDoc: 'This is the thing you need to do',
isRequired: true,
defaultValue: () => { return 'test text' },
},
},
});
List._resolveDefaults
is where I would expect the default function to be resolved server-side, but getDefaultValue
is only called for id
since name
has a null
value already.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
The defaultValue of <select> may be broken #11099 - GitHub
I would like to report a bug. In re-filing another outstanding bug that was closed despite being reproducible, I decided to create a...
Read more >Default Value in a C# Function - Stack Overflow
C++ can have default values for parameters... these parameters can be "skipped" when calling a method/function BUT the rule in C++ is that...
Read more >Be careful when using || to set default values in JavaScript
More importantly, using || to set default values breaks down when falsy values, like 0 or “”, are passed into the function. When...
Read more >Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >DefaultValue not working | Optimizely Developer Community
I added a new property and it won't set the default value. Am I missing something? This is the new property within the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanx - it seems so. It also seems that it works “on-the-fly” if it is set isRequired:false during creation (without displayed on the creation form)
Not sure why this isn’t considered a bug. So should the docs be updated to say that
defaultValue
can only be a scalar?