cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
felipito1
Helper II
Helper II

auto format a text imput as time format

Hi guys:

 

Good day, I am looking to auto format a text imput label where when the user write an hour it change auto:

 

User write --> 1910
Auto format --> 19:10

 

as you can see I want to avoid to the user write the colon.

 

Is any way to do that?

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @felipito1 ,

This will work after the user presses Enter after 4 characters.

Put this on the OnChange of the Text control (call the Variable whatever you like)

If(
   Len(YourTextBoxName.Text) > 3,
   UpdateContext(
        {
            vColon: Left(
                TextInput1.Text,
                2
            ) & ":" & Right(
                TextInput1.Text,
                2
            )
        }
    );
    Reset(YourTextBoxName)
)

Make the Default of the Text box

vColon

 

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

7 REPLIES 7
WarrenBelz
Super User
Super User

Hi @felipito1 ,

This will work after the user presses Enter after 4 characters.

Put this on the OnChange of the Text control (call the Variable whatever you like)

If(
   Len(YourTextBoxName.Text) > 3,
   UpdateContext(
        {
            vColon: Left(
                TextInput1.Text,
                2
            ) & ":" & Right(
                TextInput1.Text,
                2
            )
        }
    );
    Reset(YourTextBoxName)
)

Make the Default of the Text box

vColon

 

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.

v-xida-msft
Community Support
Community Support

Hi @felipito1 ,

Do you want the Text Input value to be formatted as time automatically after you enter 4 number value?

 

Based on the needs that you mentioned, I think the Timer control could achieve your needs. Please consider add a Timer control in your app screen. Set the Duration property to following:

1000

set the AutoStart and Repeat property to following:

true

set the OnTimerEnd property to following:

If(
   Len(TextInput1.Text) = 4,   // TextIput1 represents the Text Input box where enter your time value
   Set(
       FormattedResult,
       Left(TextInput1.Text, 2) & ":" & Right(TextInput1.Text, 2)
   )
)

Set the Visible property of the Timer control to false.

 

Set the Default property of the TextInput1 to following:

FormattedResult

Please check the following GIF screenshot for more details:

Test1.gif

Note: The OnChange property of the Text Input could be fired only when the focus is move away from that Text Input box

 

Best regards,

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank You @v-xida-msft for the alternative.

@felipito1 you might try mine as well if you want something less complex

Hi @felipito1 ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

 

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.

Hi @WarrenBelz  

Sorry my late reply, I have use that code on the "On change" property and it works really great!

 

Thank you! 

Hi WarrenBelz!

 

I tried your solution but didn't get it to work.

My question is, what should the column in sharepoint be? should i be a number or plain text? also should i use a maxLength to the text box?

 

This is my code:

If(
   Len(till_value.Text) > 3,
   UpdateContext(
        {
            vColon: Left(
                till_value.Text,
                2
            ) & ":" & Right(
                till_value.Text,
                2
            )
        }
    );
    Reset(till_value)
)

My problem seems to be that it dosn't trigger to the onChange event even if i press enter.

I also added vColon on Default

 

 

Hi @SteefQ ,

This is a very old closed post, but it should work on a Text Control - I do not know of any reason the OnChange would not trigger it.

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 (3,312)