Bonus :
If you want to ensure that the format is correct before submiting a form, you can add a an attribute to the phone input:
Name : pattern
Value : \([0-9]{3}\)\s[0-9]{3}-[0-9]{4}
The browser will prevent the submit event from happening.
@kevinwasie
You cannot access the dom element in the change workflows.
I’m working on adding the dom event to the workflows.
It should be available soon !
Hi @kevinwasie
We made a small release to add the dom event to on change workflows.
You can use event.domEvent to access it.
To get the dom element you need to use event.domEvent.target
In your case, something like : event.domEvent.target.value = event.domEvent.target.value.replace(/^(?(\d{3}))?(\d{3})-?(\d+)$/, “($1)$2-$3”);
For anyone reading this later: I ended up realizing that I was able to get the element using document.getElementById(). I used the item.index to dynamically set the id of the element to something like “phone_#”. Since I have that index number in the workflow, JS was able to make the call, and then I used the .replace function like Marc talks about above.
It goes beyond my skill set and @Marc is super busy with a couple of big releases but we’ll do our best to get back to you asap. Might take a bit longer than usual