show a text field name

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
dantomlin
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 43
Joined: Tue Feb 26, 2008 4:07 pm

show a text field name

Post by dantomlin » Tue Jul 21, 2015 2:57 pm

I was wondering if there was a way to show the field name or a field description inside the text box, maybe in a "grey" color when the field is blank to tell a user what field information should be put in the text box. I want to do this instead of having to have a a field label next to every text box. But once the user types into the filed, the data shows instead of the field name or description.

I know there is a "tool tip" feature but that only show up when they hover over the field. I want the "names" to show up when a user is looking at a blank entry form.

Any help or suggestions are always greatly appreciated...

Thanks, Dan

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9785
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: show a text field name

Post by dunbarx » Tue Jul 21, 2015 3:05 pm

Hi.

Fields have a "name" property. So you could, if the length of the field is 0, place that name into the field.

A button has, sort of built-in, a "place" for its name. Fields do not. But this ought to do the trick for you. The text attributes are all up to you. Are you OK with this? You will want to have a keyDown handler, or some other method, to release the name in favor of actual data, when the user types something. And to reinstate it should the field become empty again.

Craig Newman

dantomlin
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 43
Joined: Tue Feb 26, 2008 4:07 pm

Re: show a text field name

Post by dantomlin » Tue Jul 21, 2015 3:21 pm

if it would work, I'm ok with that but I trying to figure out how to show all of the field names when the window opens? Would I have to have an "openCard" handler to examine the fields? maybe put the fields in a group and do it that way?

Or can I use the "behavior" property?

any examples of a script would be helpful... 8)

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: show a text field name

Post by MaxV » Tue Jul 21, 2015 3:51 pm

Code: Select all

on opencard
   put the number of fields into temp
   repeat with i=1 to temp
      set the text of field i to (the tooltip of field i)
   end repeat
end opencard
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9785
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: show a text field name

Post by dunbarx » Tue Jul 21, 2015 4:30 pm

Hi.
but I trying to figure out how to show all of the field names when the window opens
Easy enough, but show them how? Like this?

Code: Select all

on opencard
  repeat with y = 1 to the number of fields
    put the name of fld y & return after temp
  end repeat
  answer temp
end openCard
This could be a long list, of course.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7266
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: show a text field name

Post by jacque » Tue Jul 21, 2015 7:57 pm

I would use behaviors. Put this into a button script and set the behavior of each field to the long ID of the button:

Code: Select all

on openfield
  if me <> the cText of me then pass openfield
  set the textcolor of me to empty
  put empty into me
end openfield

on closefield
  setupFld
end closefield

on exitfield
  setupFld
end exitfield

on setupFld
  if me <> empty then exit setupFld
  set the textcolor of me to "125,125,125"
  put the cText of me into me
end setupFld
For each field that needs this behavior, add a custom property called "cText" that contains the default text you want to display. The reason I'd use a custom property instead of the name is so we can distinguish which fields need to be set up when the card opens.

When the card opens, call this handler to initialize all the correct fields:

Code: Select all

on setupAll
  repeat with x = 1 to the number of flds
    if the cText of fld x <> "" then
      send "setupFld" to fld x
    end if
  end repeat
end setupAll
This may need adjusting depending on how you want the fields to act if a user returns to the card.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dantomlin
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 43
Joined: Tue Feb 26, 2008 4:07 pm

Re: show a text field name

Post by dantomlin » Tue Jul 21, 2015 8:11 pm

Thanks, I will give it a try...

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”