Take value from another input field in the same component

I believe this one is easy. I have a form with different fields. I want one of them to receive the value from another input element. I achieved it using dataslots and it works, but I have the feeling that I could make it without using dataslots but linking with a script to the other input element. How could I do it in the script?

Hi petoma,
What I always do in this case is to look into the Chrome debugger and see what code you have with the dataslot and from that you might be able to work out the code for doing it without the dataslot.

2 Likes

Data slots are probably the most robust way to do this. It doesn’t break if you change field names etc.

But if you don’t want to bloat your project with a lot of data slots you can achieve it with a script using React state. Input fields store their values to state based on their names.

Example

this.setState({field: this.state.anotherField});

1 Like

Thank you so much for your answers! If it is better to do it with dataSlots I will keep it as it is now. I just thought it was some kind of redundant to save a value in a dataSlot and then take the value from there when all of the data was in the same component. But it is not a big project and I can handle a couple more of dataSlots.

But the info about the state is useful for another thing I am trying but not achieving. But as it is about a different issue, I will write a different post.