field hilite different from search box

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
herbwords
Posts: 70
Joined: Sat Dec 01, 2007 2:59 am

field hilite different from search box

Post by herbwords » Tue May 29, 2012 7:06 pm

Hello,

I have a field that I do searches on and it will find what I want but the blue hilite does not match the box at certain times. I've attached a tiff as and example. If anyone has a solution to make them match or get rid of the blue hilite, thank you.

Patrick
Attachments
hilite.tiff
hilite.tiff (37.27 KiB) Viewed 5686 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: field hilite different from search box

Post by dunbarx » Tue May 29, 2012 7:34 pm

Hi.

The hilited line is the current "selectedLine". The box surounds any text that was found. They are entirely different, which is a good thing.

Is it that you want the line where the box is after a find to hilite"? With a field "yourField">

Code: Select all

on mouseUp
   find "yourtext" in fld "yourField"
   select the foundLine
end mouseUp
Yipes! Could anything be simpler or more elegant? Write back if you need more help.

Craig Newman

herbwords
Posts: 70
Joined: Sat Dec 01, 2007 2:59 am

Re: field hilite different from search box

Post by herbwords » Tue May 29, 2012 9:10 pm

OK, since it's so simple where would you put it in this script?

on mouseUp
answer "What field do you want to search?" with "Location" or "Expired" or "Lots" or "Product" or "MPL" or "Formulas" or "Cancel"
if it is "MPL" then
put "Master Part List" into it
end if
if it is "Product" then
put "Product" into it
end if
if it is "Lots" then
put "Lots" into it
end if
if it is "Expired" then
put "Expired" into it
end if
if it is "Location" then
put "Location" into it
end if
if it is "Formulas" then
put "Formulas" into it
end if
if it is "Cancel" then
exit mouseUp
end if
if it <> "" then
put it into tFld
put it into Fld "cField"
put "Master Part List,Product,Lots,Expired,Location,Formulas,order,cpound" into tValidFlds
if tFld is among the items of tValidFlds then
repeat for each item tValidFld in tValidFlds
if tValidFld = tFld then
show fld tValidFld
else
hide fld tValidFld
end if
end repeat
if it is cpound then
show fld "Master Part List"
end if
show fld "cpound"
ask "What do you want to find?"
if it <> "" then
set the uTextToFind of this card to it
focus on fld tFld
if the listBehavior of fld tFld is true then
set the dontSearch of fld tFld to false
set the lockText of fld tFld to true--
else
end if
dispatch "returnInField" to fld tFld
end if
else
answer "That field doesn't exist."
end if
end if
end mouseUp

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: field hilite different from search box

Post by dunbarx » Tue May 29, 2012 11:30 pm

Hmmm.

Your original post asked about hiliting the line of text in a field that was found with the "find" command. The standard box that LC draws around such found text does not necessarily correspond to a previously selected line, as you discovered. The code I sent uses the foundLine, a native function that returns a line number and field number (if there was a successful "find") and selects that line.

I do not see a "find" command in your script. You can always select and hilite a line(s) in a field under script control:

select line 3 of field 4
select the last line of fld "yourField"
select line 2 to 4 of fld 2

for example.

What are you asking your script to do, that involves this sort of action?

Craig Newman

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: field hilite different from search box

Post by dunbarx » Wed May 30, 2012 12:00 am

HerbWords.

On another note, after we get this "find" thing done, please think about ways to streamline your handler. There is absolutely nothing wrong with it, but there are several constructions and techniques that would make it smaller, much easier to read and much more robust. This would be a great learning experience, and give you powerful and fun tools to use in the future.

If you wish, we can tackle this whenever you want to.

Craig Newman

herbwords
Posts: 70
Joined: Sat Dec 01, 2007 2:59 am

Re: field hilite different from search box

Post by herbwords » Thu May 31, 2012 4:38 pm

OK, I was able to use your suggestion but only to make the field search start at the top of the field, this is good. Thanks.

The problem is the field needs to be changed from listBehavior ON when I click it to go to a card and listBehavior OFF when I search the field. Unfortunately, it's complicated because I have a button that changes the field from lock to unlock (for security) depending if the field has listBehavior set to true.

I actually had Ken Ray write the find feature. I put the other messy stuff in that your suggesting could be cleaned up. So any suggestions are appreciated.

Thank you

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: field hilite different from search box

Post by Klaus » Thu May 31, 2012 5:09 pm

hi herbwords,

take a look at this and read my comments.
But I think that switching from a LIST field to an editable field and back is not a good idea anyway!
Are you sure you cannot solve this in another way?

Code: Select all

on mouseUp
  answer "What field do you want to search?" with "Location" or "Expired" or "Lots" or "Product" or "MPL" or "Formulas" or "Cancel"
  
  ## Dont mess around with IT too long! 
  ## IT will change when you least exspect IT ;-)
  put it into tAnswer
  
  ## First check conditions that will cause the handler to be left!
  ## This way you avoid unneccessary IF THEN ELSE clauses!
  
  ## if the user clicked CANCEL then IT = empty!
  if tAnswer = EMPTY then
    exit mouseup
  end if
  
  ## Only on eexception, everything else is already in the variable tAnswer!!!!
  if tAnswer = "MPL" then
    put "Master Part List" into tAnswer
  end if
  
  put tAnswer into Fld "cField"
  
  put "Master Part List,Product,Lots,Expired,Location,Formulas,order,cpound" into tValidFlds
  if tAnswer is NOT among the items of tValidFlds then
    exit mouseup
  end if
  
  ## No need to check, just hide ALL fields and then show the field you want to show :-)
  lock screen
  repeat for each item tValidFld in tValidFlds
    hide fld tValidFld
  end repeat
  show fld tAnswer
  unlock screen
  
  if tAnswer = "cpound" then
    show fld "Master Part List"
  end if
  
  show fld "cpound"
  ask "What do you want to find?"
  if it = "" then
    answer "That field doesn't exist."
    exit mouseup
  end if
  
  set the uTextToFind of this card to it
  focus on fld tFld
  if the listBehavior of fld tFld is true then
    set the dontSearch of fld tFld to false
    set the lockText of fld tFld to true
  else
    dispatch "returnInField" to fld tFld
  end if
end mouseUp
Best

Klaus

Post Reply