defaultValue support
See original GitHub issueHi, there is a right way to set defaultValue to the components? by example if I set
var Formsy = require('formsy-react');
var MyAppForm = React.createClass({
enableButton: function () {
this.setState({
canSubmit: true
});
},
disableButton: function () {
this.setState({
canSubmit: false
});
},
submit: function (model) {
console.log(model);
},
render: function () {
return (
<Formsy.Form onValidSubmit={this.submit} onValid={this.enableButton} onInvalid={this.disableButton}>
<MyOwnInput name="example" defaultValue="hello" />
<MyOwnInput name="email" validations="isEmail" validationError="This is not a valid email" required/>
<button type="submit" disabled={!this.state.canSubmit}>Submit</button>
</Formsy.Form>
);
}
});
and I have MyOwnInput:
/** @jsx React.DOM */
var Formsy = require('formsy-react');
var MyOwnInput = React.createClass({
// Add the Formsy Mixin
mixins: [Formsy.Mixin],
// setValue() will set the value of the component, which in
// turn will validate it and the rest of the form
changeValue: function (event) {
this.setValue(event.currentTarget.value);
},
render: function () {
// Set a specific className based on the validation
// state of this component. showRequired() is true
// when the value is empty and the required prop is
// passed to the input. showError() is true when the
// value typed is invalid
var className = this.showRequired() ? 'required' : this.showError() ? 'error' : null;
// An error message is returned ONLY if the component is invalid
// or the server has returned an error message
var errorMessage = this.getErrorMessage();
return (
<div className={className}>
<input type="text" onChange={this.changeValue} value={this.getValue()} defaultValue={this.props.defaultValue}/>
<span>{errorMessage}</span>
</div>
);
}
});
When render the form, seems everything is ok, because the default value is being displayed, however when I click on submit, the results is
{
"example": null,
"email": "erik@localhost.com"
}
so, the default value of the input named “example” is being lost 😦
I will appreciate you help. Best Regards.
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
DefaultValue Property - Microsoft Support
Specifies a String value that is automatically entered in a field when a new record is created. For example, in an Addresses table...
Read more >HTML DOM Input Text defaultValue Property - W3Schools
The defaultValue property sets or returns the default value of a text field. Note: The default value is the value specified in the...
Read more >defaultValue support async function · Issue #11033 - GitHub
I hope defaultValue can support async function in model defintiton,for example: sequelize.define('foo', { id: { type: Sequelize.
Read more >defaultValue attribute
defaultValue attribute. The default value specified in an attribute or an element declaration or null if unspecified. If the schema is a W3C...
Read more >Default parameters - JavaScript - MDN Web Docs
However, it's often useful to set a different default value. This is where default parameters can help. In the following example, ...
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
👍 on this issue. Working on forms with default value requirements right now.
+1