Hilite text in a Field when I change focus
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 19
- Joined: Sun Apr 05, 2009 9:27 am
Hilite text in a Field when I change focus
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?
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?
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
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.
regards
Bernd
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
Bernd
-
- Posts: 19
- Joined: Sun Apr 05, 2009 9:27 am
Here is all of the code - select text of me doesn't work
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
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
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
David,
is this the posted code the problem or the solution? 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
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
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
-
- Posts: 19
- Joined: Sun Apr 05, 2009 9:27 am
why it doesn't work
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.
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
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
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.
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.