0

I have no idea how to fix this thing have been spent more than an hours to solve this problem but none of the solution fix this

So i have a combo box (Select tag element) which i would like to change the value when a modal box is opened.

I have already implement defaultValue to set the value of the combobox but it won't change. However on other input such as the notes / amount it can get the defaultValue and set it to the element.

I have try to debug the this.currState.deposit_type_id and i get the right value

But in fact it won't change

it always refer to the default value

I have made several type of this thing but none of them has ever had this bug

Here's the screenshot for the code and the image

These are the code to pass the data from parent's component, and deposit type for all the value i will put on the combo box

This is the code to pass the data from parent's component, and deposit type for all the value i will put on the combo box

enter image description here

This is the code that i used for set the default value when the modal box is opened

enter image description here

This is the result, it supposed to choose "Kas Besar", yet it choose "Deposit Type" instead

2

1 Answer 1

0

Not sure as I am not able to try it now but you could try to add your value argument for input's html like this:

value={ this.state.currData && this.state.currData.deposit_type_id  }

But it would be better to get currData from props. So this.props.currData.

Sign up to request clarification or add additional context in comments.

8 Comments

as far as i know we're not allowed to use value to set for the value, we should use defaultValue
But you should not use your props in state like you did in componentWillMount. Use props in render function and initialize state in constructor function.
But i need the value from my props to set the value on my state. Can i do that in my constructor? Get the props then set the state on constructor
Why do you need it that way?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.