Setting textBefore in script


Is it possible to set the textBefore on a textinput from within a JS query?

I have a text field which shows a payment type and payment id. I want the textBefore to show the payment type (e.g card / bank transfer) and then the actual text value to show the relevant id.

I've managed to set this fine with the data direct from a SQL query. However when I try and update the textBefore to a different value from a script it wont allow it.


Hey @Rob_Faulkner!

It doesn't look like there's currently a set method for the prefix text on a text input. If you'd like to dynamically set it you might try passing the value of a temp state to that field, which you can then set dynamically. Does that work?

Hi @Kabirdas, thanks for getting back to me. As a fix, so I could carry on I created a hidden field and then set that to a new value in the script. Then referenced that field in "textBefore".

It sounds a little convoluted I'm sure. However, as I'm pulling a number of records from a Db table I don't think a temp state would work as I would need one for each record when it first loaded?

Long story short, I think the hidden field will probably work better for me here unless I've missed something. Was just hoping there was some way of updating it directly and I was just being stupid! :slight_smile:

Thanks again!

Temp states are super flexible! If you want to set and edit multiple records within the state you can try using the setIn method which lets you specify a path that you want to save a particular value under in the temp state. It works really well with the i variable for event handlers in tables and listviews. Or with something like {{}} to track the id of the component:


Ah interesting @Kabirdas. Ill look at doing it this way! Also useful to know for the future.
Thanks for looking into this for me and the examples.