DesktopTextField - apply Format to user input

Having a DesktopTextField that receives a default value when the window opens. The default value is properly formatted by using

baseAmount_txt.text = Format(baseAmount, “###,”)

When editing the value (add a ‘0’ i.e.) me.Format is not applied when the field loses focus. What am I missing?

There isn’t anything on that window to take focus away from the field.
It works here when I provide a control that can actually take focus.

(The Close button will, but by then you’ve closed the window and can’t see the Format happen)

That means hitting tab or enter does not take the focus from the field?

If there is nothing else to take focus, no.
Add another text field and you should see it work.

1 Like

That works, thanks!

Figured out how to make it work with a single text field:
Add a ‘KeyDown’ event to the text field with this action:

If Key.Asc = 13 Then

Not sure if this is good OOP style.

Are you sure you’re not looking for a ValidationMask?

Not in this case, but this is on my list of things learn in Xojo. Without your initial hint I would have spent hours chasing the focus thing. Thanks!

It’s the same thing as Format but restricts entry rather than deleting non-compliant data. It’s basically your every keystroke check, but restrictive.

If you aren’t trying to restrict input, then yes you’ll need to find a way to apply Format at the interval you desire. If what you’ve posted is working the way you like then great!

1 Like

Ok, so ValidationMask can be used to restrict i.e. data entry to numbers 0-9, like a filter. Then Format applies i.e. thousands separator and number of decimals.