question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

defaultValue callback is never called

See original GitHub issue

What you were expecting: I’m trying to setting a default uuid on a TextInput field as suggested in the documentation.

<TextInput
    disabled
    source='id'
    defaultValue={() => uuidv4()}
/>

but it seems that the callback is never called and the field is empty even on form submit. By doing the following:

<TextInput
    disabled
    source='id'
    defaultValue={uuidv4()}
/>

The defaultValue appears in the TextInput but in an ArrayInput the value would be always the same for each Array element because uuid4() is called only once.

Environment

  • React-admin version: ^3.5.0
  • React version: ^16.13.1
  • Browser: Chrome 81 - Mac

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fzaninottocommented, May 13, 2020

No, cloneElement clones an element with its props.

0reactions
gpietrocommented, May 13, 2020

I’m having trouble using react-admin locally with npm link so I’ll try here. Could it be the missing

defaultValue: input.props.defaultValue

while cloning element the origin of the problem?

https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/form/SimpleFormIterator.js#L153

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set a default value for callback function? - Stack Overflow
log(`The Answer is ${cb(num1,num2)}`) } cal(3,2,mul); Here the code I tried to set a default value to callback function. let sum = (num1,num2) ......
Read more >
Default value callback not called when used in recursion ...
If I'm recursively prompting a set of questions, the default value of a question is the generated value from the first iteration.
Read more >
ReturnType of optional callback parameter? : r/typescript
I suspect the issue is that you are trying to assign a default value for a type that is generic. The default value...
Read more >
Array.prototype.reduce() - JavaScript - MDN Web Docs
The reduce() method executes a user-supplied "reducer" callback function on ... reduce() does not mutate the array on which it is called, ...
Read more >
TypeError: callback is not a function in JavaScript | bobbyhadz
Alternatively, you can define a default value for the callback parameter. This way you won't get an error even if no parameter is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found