LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Placeholder text in String Control

LV 2013 SP1, Win7

 

For years OS X, and lately Windows, has had the idea of "Placeholder" text for string-entry fields (controls).

 

The idea is that if the field is blank, then it shows some help text ("enter your name here") in gray italics in the field.

 

It's gray to indicate that it's not the real text in that field.

 

As soon as you tab into or click into that field, the placeholder disappears, and the text you type is normal black.

 

If you leave the field (tab/click elsewhere), if the field is blank, the placeholder comes back; if not, the text you typed remains.

 

I have a situation where this is the perfect solution, but there is no built-in LV facility for doing it (Is it too late to sneak it into LV2014? 😉

 

The pseudo-code for what I want to do is this:

 

When writing control:

    If new value == blank

        Set control value to placeholder text

        Set control font to gray/italics

    else

        Set control value to new value

        Set control font to black/normal

    end

 

When focus arrives:

    If control font == gray

        Set control value to blank

        Set control font to black/normal

    end

 

When focus leaves:

    if control value == blank

        Set control value to placeholder text

        Set control font to gray/italics

    else

        Set control font to black/normal

    end

 

When reading control:

    if control font == gray

        report blank

    else

        report control value

    end

 

--- That seems easy enough, except I see no way for LV to trigger the focus arriving / leaving.

The EVENT structure has no such events.  

I don't see an INVOKE NODE that would help.

I don't see a PROPERTY that would help.

 

I suppose I could detect a MOUSE DOWN .OR. KEY DOWN and use that as the FOCUS ARRIVES trigger.

That's a slight change in the behavior, but I could live with it.

 

But I don't see a way to detect the focus leaving.

 

Any ideas?

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 1 of 11
(5,785 Views)

Hi Steve,

 

you surely knew my LabVIEW Idea before…

 In the comments you will find a (partially) workaround.

 

Other idea:

You could make your string control transparent and place your "placeholder text" behind the control to fake the ValueChange. Now you only need to change the background color of the string control whenever the string gets focus…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 11
(5,783 Views)

Hmmm.  There is a VI method called "Find Control with Key Focus".  That would mean polling though.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 3 of 11
(5,774 Views)

you surely knew my LabVIEW Idea before…

 

No, I didn't, and don't call me Shirley.   😉

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 4 of 11
(5,771 Views)

in the comments you will find a (partially) workaround.

 

That project has problems, though.

 

#1.  it doesn't work in DevSys, only the EXE.  

#2... It doesn't work when you TAB into/out of the Xctl.  Only when you CLICK in / out.

#3... Clicking ANYWHERE produces the LOST FOCUS message, even if it didn't have focus.  (comment 3 on the panel is incorrect)

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 11
(5,763 Views)

You could make your string control transparent and place your "placeholder text" behind the control to fake the ValueChange. Now you only need to change the background color of the string control whenever the string gets focus…

 

Yes, but it's the "whenever the string gets focus" that is stumping me.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 6 of 11
(5,761 Views)

For the record, the KEY FOCUS property takes 17 uSec to execute, when linked directly to a string control.

It takes 19 uSec when using a REFERENCE to the control.

 

using the FIND CTRL WITH KEY FOCUS method, it takes 2.4 uSec to execute that and compare the result to a known refererence.

 

This on a 3.4 GHz i7.

 

My guess is that KEY FOCUS property uses FIND CTRL WITH KEY FOCUS and looks for a match in a table.  

But it doesn't seem to make a difference to the 17 uSec if there are two or twenty controls, so maybe not.

 

 

Anybody know if LV2014 includes this?  I'm not a beta tester this year.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 7 of 11
(5,755 Views)

The ViBox - XControls toolkit/addon/package from SAPHIR includes an XControl with this functionality (placeholder text in string controls)...

 

It's in the LabVIEW Tools Network:

vipm://saphir_lib_vibox_xcontrols?repo_url=http://ftp.ni.com/evaluation/labview/lvtn/vipm

 

http://www.saphir.fr/en/produits/vibox---xcontrols-9.html

 

Maybe that will fit the bill?


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 8 of 11
(5,749 Views)

ViBox - XControls toolkit/addon/package from SAPHIR

That has license fees associated, my situation cannot handle that.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 9 of 11
(5,731 Views)

The FIND CTRL with KEY FOCUS tells lies though.

 

Given a VI reference, it will tell you if a string control at the top level of that panel is focused.

 

If the control is inside a TAB, it will find it.

 

However, if the string control is inside a CLUSTER, it says there is no control with focus.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 10 of 11
(5,723 Views)