cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
elaaadani
Helper V
Helper V

Put a - before the last character

Hi, I need to put a - before the last character. The field will receive 1234567890 and I need to put 123456789-0
How can I do this?
Thank you very much.

1 ACCEPTED SOLUTION

Accepted Solutions

@elaaadani ,

On the OnChange of the Text Box

UpdateContext(
   {
      varDash: 
      With(
         {wChar: Self.Text},
         Left(
            wChar,
            Len(wChar) - 2
         ) & "-" & 
         Right(
            wChar,
            1
         )
      )
   }
);
Reset(Self)

On the Default of the Text Box

If(
   !IsBlank(varDash),
   varDash,
   Parent.Default
)

On the OnVisible of the screen and at with any Save code (if you do not leave the screen)

UpdateContext({varDash:false})

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

View solution in original post

14 REPLIES 14
WarrenBelz
Super User
Super User

Hi @elaaadani ,

Try this

With(
   {wChar:YourTextControlName.Text},
   Left(
      wChar,
      Len(wChar)-2
   ) & "-" & 
   Right(wChar,1)
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

It does not work. It says it has a number of invalid arguments. Besides an unexpected character in this line

{wChar:YourTextControlName.Text},

 I put this

 

With(
   {wChar:RutOnombre.Text},
   Left(
      wChar,
      Len(wChar)-2
   ) & "-" & 
   Right(wChar,1)
)

 

 

Hi @elaaadani ,

It does work as below using a text box named exactly as your example

AddDash.png

 

InsertDash.gif

What are you doing different?

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

 

elaaadani
Helper V
Helper V

@elaaadani ,

Are you trying to do it to the same text box as the input? That is a bit more complex. Please confirm That code was designed to write to the source and then display it.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

@WarrenBelz Yes, it's the same text box as the input

@elaaadani ,

On the OnChange of the Text Box

UpdateContext(
   {
      varDash: 
      With(
         {wChar: Self.Text},
         Left(
            wChar,
            Len(wChar) - 2
         ) & "-" & 
         Right(
            wChar,
            1
         )
      )
   }
);
Reset(Self)

On the Default of the Text Box

If(
   !IsBlank(varDash),
   varDash,
   Parent.Default
)

On the OnVisible of the screen and at with any Save code (if you do not leave the screen)

UpdateContext({varDash:false})

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

elaaadani
Helper V
Helper V

Hi @WarrenBelz 

It doesn't work for me. I always get this same error !

Number of invalid arguments. 1 was received, but 2 were expected

elaaadani_0-1611159995854.png

 

@elaaadani ,

Here is the exact code I used and it worked exactly as expected in testing

AddDash2.png

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,648)