How to replace a WORD in an input with ANOTHER WORD by workflow?

How to replace a WORD in an input with ANOTHER WORD by workflow?
What I want to do is:
1, select the word " SPORT" from input field
2. click modify button
3. replace the original word “SPORT” with “^^ running ^^”

this is the editor link if someone wants to try on it: https://bubble.io/page?name=index&id=testtest556&tab=tabs-1

Try running the Run javascript action you get within the toolbox plugin and putting this into it…

var elem = document.getElementById('bTGyS');
var value = elem.value.replace('SPORT', 'RUNNING');
elem.value = value;
1 Like

I don’t know if this helps, but…

I built a contract system which uses substitution fields. When the client creates a new contract from a template. I cycle through the template, find the placeholders (in your case, “SPORT”) and replace it with a data value (in your case “running”):

Thanks @pork1977gm . Sorry for late reply.
Acctrually , What I want to replace is not the word “SPORT” (it is just an example), but any random word that is selected by user in an input.

So I think the key here is: How to detect that random word in an input which is selected by user?
Do you have any suggestion on that?

Thanks in advance.

Thanks @firstfifteensoftware Sorry for late reply.

Acctrually , What I want to replace is not the word “SPORT” (it is just an example), but any random word that is selected by user in an input.

So I think the key here is: How to detect that random word in an input which is selected by user?
Do you have any suggestion on that?

Thanks in advance.

I have a boilerplate contract that (before any substitution) looks like this:

Screenshot 2022-12-28 at 5.31.47 AM

I just added two input text fields and keyed in these values:

Screenshot 2022-12-28 at 5.32.22 AM

I then ran this chunk of code:

And the result in my contract was this:

Screenshot 2022-12-28 at 5.32.04 AM

So I was able to replace any value that was entered with a different value that was entered.

Does that help at all? Your input field could be just a text field, dropdown, whatever.

Hi there, @Lionot… I just made a quick example that does exactly what you described, and I used this plugin in the example. A combination of that plugin and a workflow on the modify button that sets a custom state to the original text with a find and replace of the plugin’s selected text does the trick, so give it a shot.

Hope this helps.

Best…
Mike

Edit: I just saw the editor link in your initial post, so I popped in there and set it up, and it appears to be working as expected.

Thanks @firstfifteensoftware

Hi @mikeloc
This is what I want.
But one more question here: When there are more than one words named “SPORT” in text field, it will replace all “SPORT”.

How to only replace the selected “SPORT” instead of all words named “SPORT”. I attached a screen shot