Page 1 of 1

Hilite text in a Field when I change focus

Posted: Thu Apr 16, 2009 9:38 am
by DavidBurleigh
I have tried:

Select text in field fieldname

to get it to hilite, but it doesn't work.

When someone enters bad data, I want to have the
bad data automatically selected so that when they
10 key in a new date into the field the don't have to
grab the mouse and select the data first.

What I do is set a custom property that the data is bad.
when the focus changes to a new field, the new field
reads the property and if it's set properly, it then
changes the focus back to the previous field with the
bad data in it. when that field gets the focus again
I check the property and then want to have the
data selected and hilited for replacement with
correct data.

Any ideas?

Posted: Thu Apr 16, 2009 10:26 am
by bn
Hi David,

if you put this code into the field that you want to control the data entry of then this works.
Do you have a special reason to do it with a custom property, from what I understand you just need the custom property as a flag for correct text entry. It seems easier to test for correct text entry when the user leaves the field.
e.g.

Code: Select all

on closefield 
    if text of me is not a number and not (text of me is "") then select text of me
end closefield
regards
Bernd

Here is all of the code - select text of me doesn't work

Posted: Thu Apr 16, 2009 9:07 pm
by DavidBurleigh
on closeField -- if the information changes
put convertDate(me) into checkval
if checkval = "Bad Data" then
put empty into me
set the badDateProperty of this card to true
else
put checkval into me
set the badDateProperty of this card to false
end if
end closeField

on exitField -- if the information doesn't change
put convertDate(me) into me
set the badDateProperty of this card to false
end exitField



on openField
put the originalmodifiedProperty of this card into me
if me is not empty then select the text of me
end openField



function convertDate inputInfo
put "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec" into monthsField
put "31,28,31,30,31,30,31,31,30,31,30,31" into daysField
put char 1 to 2 of inputInfo into monthField
put char 3 to 4 of inputInfo into dayField
put char 5 to 6 of inputInfo into yearField

if (monthField >= 1) and (monthField <= 12) then

-- calculate if leap year
if ((yearField mod 4) = 0) and (monthField = 2) then
put 29 into maxdays
else
put item monthField of daysField into maxdays
end if

if (dayField >= 1) and (dayField <= maxdays) then
set the originalmodifiedProperty of this card to inputInfo
return dayField &" " & item monthField of monthsField & " " & yearField
else
answer "Bad Data"
return "Bad Data"
end if

else
answer "Bad Data"
return "Bad Data"
end if

end convertDate

Posted: Thu Apr 16, 2009 9:52 pm
by bn
David,
is this the posted code the problem or the solution?

Code: Select all

on openField
    put the originalmodifiedProperty of this card into me 
    if me is not empty then select the text of me 
end openField 
works for me

skimming over your code I dont see why it should not hilite the text. I didnt put your original code to work. Please tell us what happens when you run it.

regards

Bernd

why it doesn't work

Posted: Fri Apr 17, 2009 2:07 am
by DavidBurleigh
I figured out why it doesn't work, but haven't found a solution.

When I tab to the field, it works. When I click on the field
and openField triggers, the placing of the cursor wipes out
the hilite.

Re: why it doesn't work

Posted: Fri Apr 17, 2009 5:17 am
by sturgis
Would something like this work?

Code: Select all

on openField
   put true into thisIsInvalid
   if thisIsInvalid then
      send "invalidDate" to me in 0 seconds
   end if
end openField

command invalidDate
   select the selectedLine
end invalidDate

DavidBurleigh wrote:I figured out why it doesn't work, but haven't found a solution.

When I tab to the field, it works. When I click on the field
and openField triggers, the placing of the cursor wipes out
the hilite.

Re: why it doesn't work

Posted: Fri Apr 17, 2009 6:03 am
by sturgis
Due to some strangeness I don't entirely understand you should change the command invalidDate (just my example) to check for an empty selectedChunk.
The other way there was an error if the field in question was focused, and you tab to another program, then click somewhere other than the field to return focus to the app. The new code below works around this problem.


Code: Select all

on openField
   put true into thisIsInvalid
   if thisIsInvalid then
      send "invalidDate" to me in 0 seconds
   end if
end openField

command invalidDate
   if the selectedChunk is empty then
      break
   else
      select the selectedLine
   end if
end invalidDate
sturgis wrote:Would something like this work?

Code: Select all

on openField
   put true into thisIsInvalid
   if thisIsInvalid then
      send "invalidDate" to me in 0 seconds
   end if
end openField

command invalidDate
   select the selectedLine
end invalidDate

DavidBurleigh wrote:I figured out why it doesn't work, but haven't found a solution.

When I tab to the field, it works. When I click on the field
and openField triggers, the placing of the cursor wipes out
the hilite.