0

I am trying to pass the value of the ImageTag entered by the user as well as the locationValue selected from the dropdown menu(selectField of material-ui) to the server via socket.

Here is my code:-

var BaseImageDetails = React.createClass({
getInitialState:function(){ 
    return{
        imageTag: '',
        locationValue: ''
    };

},
contextTypes: {
    socket: React.PropTypes.object.isRequired
},

handleImageChange:function(event){
    this.setState({imageTag: event.target.value});
    console.log(imageTag);
},

handleLocationChange:function(event){
    this.setState({locationValue: event.target.value});
    console.log(locationValue);
},


clickedBase: function(e){
    e.preventDefault();
    this.context.socket.emit("baseImageSubmit",{imageTag},{locationValue});


},

render(){
    console.log("wwooowwowow" , this.props.locationDetails);
        var locationItems = this.props.locationDetails.map(function(locationItem){
            return <MenuItem value = {locationItem} primaryText = {locationItem} />
        }.bind(this));      

    console.log("locationItems------------",locationItems);
    return(
        <div>             
            <Card>
                <CardHeader
                  title="Please provide the following details ? "
                  actAsExpander={true}
                  showExpandableButton={true}
                />
               <form onSubmit = {this.clickedBase} >
                    <TextField hintText="Image Tag" 
                    floatingLabelText="Image Tag"
                    value = {this.state.imageTag} onChange = {this.handleImageChange}/>
                    <Divider />
                    <SelectField 
                        fullWidth={true}
                        hintText="Select the location of your base-image Dockerfile"
                        onChange = {this.handleLocationChange}
                        value = {this.state.locationValue}                                                                                     
                        maxHeight={200}>
                        {locationItems}
                    </SelectField>
                    <Divider />
                    <RaisedButton label="Secondary" primary={true}
                     label="Build" secondary={true} 
                     type = "submit" />
                </form>                              
                </Card>
             </div>
        );
    }
});

But while consoling it prints "Uncaught ReferenceError: locationValue is not defined" both for the locationValue and imageTag. Can you guys help me where I am doing wrong....

Joy
  • 9,430
  • 11
  • 44
  • 95
Paramveer Singh
  • 51
  • 1
  • 10
  • Seems your line `this.context.socket.emit("baseImageSubmit",{imageTag},{locationValue});` should be changed to `this.context.socket.emit("baseImageSubmit",{imageTag: this.state.imageTag},{locationValue: this.state.locationValue});` – Joy Sep 20 '16 at 11:46
  • Yeah Man!!!! Thanks a ton – Paramveer Singh Sep 20 '16 at 13:22

1 Answers1

0

When you write {imageTag}, that's the same as writing {imageTag: imageTag}, and there's no local variable called imageTag on your scope.

You probably mean

this.context.socket.emit("baseImageSubmit",{
    imageTag: this.props.imageTag
},{
    locationValue: this.props.locationValue
});

Or if you are trying to use destructuring assignments

const {imageTag, locationValue} = this.props;
this.context.socket.emit("baseImageSubmit",{imageTag},{locationValue});
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217