0

i'am using backendless api to create simple crud application. this is my table schema:

products table:

  • name (string)
  • price (double)
  • description (text)

i use input component from native base to get the value from user. But i have problem with price, when i input price 5000 then in the database the value is not 5000 but 892350512, i think this is happen because the value from onChangeText is string and i confuse how to parseInt() in my state.

this is my code:

state = { data: {} }

allProduct(){
    axios.get(`${uri}/products?sortBy=created%20desc`).then(result => {
        this.setState({
            data: result.data
        })
    })
}

handleSubmit(){ 

    axios.post(`${uri}/products`, this.state.data).then(result => {
        if(result.data){
            this.allProduct,
            alert("Succes!")
        }
    })

    // alert(JSON.stringify(this.state.data))
}

And this is my form code to get value from user:

<Label style={styles.batasAtas}>Harga</Label>
<Item regular>
    <Input onChangeText={(price) => this.setState({data:{...this.state.data, price}})} keyboardType = 'numeric'/>
</Item>
masdap
  • 161
  • 14

1 Answers1

0

You can do:

<Input onChangeText={(price) => this.setState({data:{...this.state.data, parseInt(price)}})} keyboardType='numeric'/>

To change the price to an integer.

Colin Ricardo
  • 16,488
  • 11
  • 47
  • 80