-
Notifications
You must be signed in to change notification settings - Fork 47k
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 does not work with input when type is set to submit #14785
Comments
Someone please correct me if I'm wrong but this might have been intentional? I was curious so stepping through the code, it looks like it bails out from setting the initial
Looking at the #12872, it seems the reason for this is that the browser itself has a |
@augbog I agree with you, I tracked until seeing it code. I'm thinking on this possible fix: when the if (_initialValue) {
node.value = _initialValue;
} Something like it: var _initialValue = toString(node._wrapperState.initialValue);
// Avoid setting value attribute on submit/reset inputs as it overrides the
// default value provided by the browser. See: #12872
if (isButton && (props.value === undefined || props.value === null)) {
if (_initialValue) {
node.value = _initialValue;
}
return;
} I did this local fix and is working here. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When you use uncontrolled
<input type="submit" />
and setdefaultValue
attribute, it would be ignored in versions 1.5.0 or higher (there would be novalue
attribute in the HTML result). It was working correctly in older versions. Looks like onlytype="submit"
is affected, for other input typesdefaultValue
behaves correctly.If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
Correct behaviour with react 16.4.2: https://codepen.io/anon/pen/zePmrZ
Incorrect behaviour with react 16.8.1: https://codepen.io/anon/pen/PVOyqV
What is the expected behavior?
When
defaultValue="foo"
is set on<input type="submit"/>
it should result in<input type="submit" value="foo" />
in the HTML result.Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
All versions starting from 16.5.0
The text was updated successfully, but these errors were encountered: