Skip to content
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

text field getValue from dynamic function error #2524

Closed
munkh-altai opened this issue Dec 15, 2015 · 4 comments
Closed

text field getValue from dynamic function error #2524

munkh-altai opened this issue Dec 15, 2015 · 4 comments
Labels
component: text field This is the name of the generic UI component, not the React module!

Comments

@munkh-altai
Copy link

Thank you for your create UI.

I am trying getValue from dynamic function

const getRefValue = (name) => {
return this.refs[name].getValue();
};

when i call this function i got error ("Uncaught TypeError: _this.refs[name].getValue is not a function")

but if i try this.refs['refName'].getValue() like this fine how to make dynamic function ?

@alitaheri
Copy link
Member

@altaihero can you please provide the code that calls this function? it seems like the name is not provided a valid ref string.

@munkh-altai
Copy link
Author

thank for reply

this is my code
import React, { Component, PropTypes } from 'react';

//form fields

import TextField from 'material-ui/lib/text-field';
import Checkbox from 'material-ui/lib/checkbox';
import RadioButton from 'material-ui/lib/radio-button';
import RadioButtonGroup from 'material-ui/lib/radio-button-group';
import Toggle from 'material-ui/lib/toggle';

import FlatButton from 'material-ui/lib/flat-button';
import RaisedButton from 'material-ui/lib/raised-button';
import FloatingActionButton from 'material-ui/lib/floating-action-button';

export default class Form extends Component {
saveHandler(){
const getRefValue = (name) => {
return this.refs[name].getValue();
};

    console.log(getRefValue('test'))
}
render() {
    const { formData, saveHandler, changeHandler  } = this.props;

    const formFields = formData.map((field) => {
        if(field.type == '--text')
            return  <div key={field.column}>
                        <TextField
                            name={field.column}
                            ref={field.column}
                            defaultValue={field.value}
                            floatingLabelText={field.title}
                            onChange={changeHandler}
                            hintText={field.title} />
                    </div>
        else if(field.type == '--checkbox')
            return  <div key={field.column}>
                        <Checkbox
                            name={field.column}
                            ref={field.column}

                            defaultValue={field.value}
                            onCheck={changeHandler}
                            label={field.title}/>
                    </div>
    })

    return (
        <div className="card-body">
            <div className="row padding" >
                <hr/>
                <div className="col-md-12 col-lg-12 col-sm-12">
                    <h3>rr</h3>
                    <form action="" >
                        <div>
                            {formFields}
                        </div>
                        <div>
                            <FlatButton label="Cancel" primary={true}  href="#/" linkButton={true}/>

                            <FlatButton label="Save" secondary={true} type="submit" onClick={this.saveHandler.bind(this)}/>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    )
}

}
Form.defaultProps = {

};

Form.propTypes = {
formData: PropTypes.array.isRequired,
changeHandler: PropTypes.func.isRequired
};

@alitaheri
Copy link
Member

I don't see any component having ref="test".

which of these components cannot be referenced?

@munkh-altai
Copy link
Author

test is just example i was just try get ref value from function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

3 participants