Delete only single character before cursor position in text box

howto

#1

if the text of text box is 12345 .
and user set the cursor position after number 3 for example , and click the button .

i want if button clicked , delete number 3 , then the text of text box become 1245 instead of 12345


#2

To do this, you’ll need to use Taifun’s Textbox Extension.

This will allow you to get the cursor position from the textbox.


#3

i don’t understand how to delete the character that’s before the cursor by this extension ?


#4

You don’t just tell the textbox to delete the character before the cursor.
You have to get the cursor position and use it to eliminate the character in that number minus 1 (because your cursor will be in the 4th position and you need to eliminate the 3rd character).

Use the SEGMENT block to get everything before the cursor position, and again to get everything after the cursor position.


#5

yes that i want , how i get everything after the cursor ?


#6

That extension has a block that will give you the position of the cursor within a text box.

If you know the position that the cursor is at, then you can use the regular built-in text blocks to “cut out” the part you don’t want and re-combine the parts you do want.

Here is a working example, however it does not include any debugging (i.e. if the cursor is at the beginning of the textbox, it will cause an error.)


#7

i tried this before , but not working .
but when i try your blocks , it’s worked , i don’t understand how :smile:

generally , thank you for your help :slight_smile:


#8

Yeah, it’s pretty easy to get lost in the math when subtracting characters within the string, I got lost a few times just putting this together. LOL but I’m glad this helped you out.


#9

@Nader_El-Sayed,

You asked the same question in another community.
I understand that you didn’t receive a complete solution there and you received one here.
However, you should only ask the question in the community of the builder you are currently working with.


#10

Yes i understand you, but i already use appy builder, thunkable, kodular and bolck2code, because every web site has some diffrint blocks :heart::blush:


#11

You could have gotten a much earlier response if the request was only made in one of the communitys and because of that I choosed not to

bild|609x171

Btw @DocDrydenn we used almost the same solution and one more thing what happens if cursor is at the beginning

/Boban


#12

Well, the way my blocks handle this is that it just subtracts from the current position. If the cursor is at the beginning, position 1, and you subtract one, you’d end up with a zero. This will throw a length error in the segment block. To fix this, you’d just need to add an if block into the mix to make sure you are not at position 1 when the code is executed. (see below)