I took a crack at this and was able to come up with something that resembles the behavior you’re describing. It’s not the most simple setup but it works!
Credit Card Form Example.rp (49.6 KB)
Background:
It does require a lot of conditional logic and properties to dissect the text and its properties. If you want to create a more simple one without the dashes, then it can be pretty straightforward as you’re just removing underscores starting from the front; then replace them as you backspace.
If you want to include the dashes as well, then one way I found was to create conditions/cases for each instance of when we want to inject a dash as opposed to an underscore. There probably is a more efficient way of doing so… but I left it at this before getting lost further down the rabbit hole.
Setup:
I used two text fields where the input field is left blank and the output field contains the underline structure. The input will be on top and set at a low opacity. This will be what the user will interact with and contain all of our interactions that will modify the actual output.
For the simple version, there are two main expressions used for typing (removing underscores) and backspacing (adding underscores).
Typing: [[This.text + Target.text.slice(This.text.length)]]
Backspacing: [[This.text + “_” + Target.text.slice(This.text.length+1)]]
Essentially, we are stitching what we currently have on our input (“This.text”) with what we have on our output (“Target.text”). We will use “.slice” and “.length” to determine how much we want to add of the current output structure.
When we consider a credit card form with the dashes, this can become unwieldy as we have to account for each dash and backspace and all of the different behaviors that accompany it as a result.
Here are some reference pages of our docs just in case:
Text Properties
Conditional Logic