How to get current value?
See original GitHub issueFor example I have a form with few select items. I would like to validate this form when user submits the form. So, I would like to have a getValue
method the select component to use it like below:
var Form = React.createClass({
render: function () {
return (
<form onSubmit={this.submit}>
<Select ref="one" ... />
<Select ref="two" ... />
<Select ref="three" ... />
...
<button type="submit">Submit</button>
</form>
);
},
submit: function () {
if (this.validate()) {
// send form to the server
} else {
// show errors
}
},
validate: function () {
var isValid = true;
for (key in this.refs) {
var component = this.refs[key];
var value = component.getValue ? component.getValue() : component.getDOMNode.value;
// validation ...
});
return isValid;
}
})
At the moment I see only one way to do this using onChange
for each component and store the values in some place. But I think, with getValue
method it will be more clear and simple.
Issue Analytics
- State:
- Created 8 years ago
- Comments:14
Top Results From Across the Web
How to get current value of RxJS Subject or Observable?
The only way you should be getting values "out of" an Observable/Subject is with subscribe!
Read more >How to Get the Current Value of an RxJS Subject or Observable
Approach: 1 ... The better approach is always to use subscribe to get a value out. ... const source = from([1, 2, 3,...
Read more >CURRENT-VALUE function - Progress Documentation
Returns the current INT64 value of a sequence defined in the Data Dictionary. Syntax CURRENT-VALUE ( sequence [ ... GET-EFFECTIVE-TENANT-ID function.
Read more >How to get current value for a referenced field? - ServiceNow
I get the parent.name from the current. value which is a text field, but the challenge I am having is that getting the...
Read more >How to get current value of RxJS Subject or Observable
If you want to have a current value, use BehaviorSubject which is designed for exactly that purpose. BehaviorSubject keeps the last emitted ...
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
The Usage documentation shows that you can use the
onChange
prop on the Select component directly.I think that the README answers this question and that this issue can now be closed.
@kevinrue, @benrolsen code snippet simply does is:
Assigns name props to React-Select component
then access/get the hidden input field using jquery selector where the selector is $( “input[name=‘name_prop_value_givenToReactSelect’]” ).val() which returns the hidden input field value