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.

How to get current value?

See original GitHub issue

For 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:closed
  • Created 8 years ago
  • Comments:14

github_iconTop GitHub Comments

98reactions
radarcommented, Aug 17, 2015

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.

20reactions
aqumuscommented, Feb 12, 2017

@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

<Select name="anyCustomName"/>
var hiddenInputValue = $( "input[name='anyCustomName']" ).val();
Read more comments on GitHub >

github_iconTop 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 >

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