Clearing Search

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
williamsc84
Posts: 7
Joined: Sun Aug 06, 2017 1:54 pm

Clearing Search

Post by williamsc84 » Sun Aug 06, 2017 2:09 pm

Hi all, I'm brand new to LiveCode and reasonably new to coding.

I am trying to build an app where there is an input field and a scrolling list field, when you enter something into the input field it filters the data in the scrolling list field and you can then choose your selection.

At the moment this is working as expected on first attempt, However when i go back to it for the second time and i enter something into the input field, it is only filtering the data on my list search.

For example, if the scrolling list has A,B,C,D in it, on the first time i search if i Type in C it will filter directly to C.

If i navigate away and back, on the second time i search, even though I can see A,B,C,D in the scrolling list field, when i type in the box either A,B or D it won't find it. It only seems to search anything that comes under C.

If I click away and go back again for the 3rd time, it works as expected.

Any hints as to where I should be looking to fix this?

This is the code of my search field

Code: Select all

local sFieldContent

on keyUp pKey
   if sFieldContent is empty then
      put the text of field "ScrollingList" into sFieldContent
   end if
   filter sFieldContent with "*" & the text of me & "*"
   put sFieldContent into field "ScrollingList"
end keyUp
and this is the code of that puts the data into my scrolling list field each time the card is loaded

Code: Select all

on preopencard
   put URL "url to my text file" into field "scrollingList"
end preopencard
Note - it wouldn't let me post my URL - the text file just includes a list of text data in alphabetical order.

I actually have two issues here.

Issue 1 - When i go to the card on the first attempt and type, it will filter correctly and do what i expect, when i navigate away from card and back to the card, even though all of the data is in the field, it only searches within the parameters of my last search. Note - if i navigate away and then back for a 3rd time, it seems to resent and works as i expect

issue 2 - If for any reason I decide to change my search half way through, for example i type in "a" in to the input field and the scrolling list shows all options beginning with "a" if i backspace and type in "b" it doesn't find anything as the scrolling list now only contains anything that has "a" in it.

I hope I have explained this well enough. Any advice is much appreciated. Thanks in advance

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Clearing Search

Post by shaosean » Sun Aug 06, 2017 2:48 pm

I think you need to empty out, or update, your sFieldContent variable

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2588
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Clearing Search

Post by jmburnod » Sun Aug 06, 2017 3:13 pm

Hi William,
Welcome
Just after a look to your script
1. I understand you put search results into field "ScrollingList"
Names of controls make development too easy
If you search in this fld your script search in the previous search results.
2. KeyUp is not sent by backspace, but a rawkeyUp is sent
3. TextChanged instead Keyup is probably a best way.

Create to fields and name them "fSearch" and "fMyFoundContent".
Set the script of your cd to this:

Code: Select all

local sFieldContent,sMyFoundContent
on opencard -- just to be sure that is something in sFieldContent
   put "a,b,c,d" into sFieldContent
   replace "," with cr in sFieldContent
end opencard

on textchanged
   if the short name of the target = "fSearch" then
      if sFieldContent is empty then
   --      put URL "url to my text file" into sFieldContent--  for your text file
         put the text of field "fMyFoundContent" into sFieldContent
      end if
      get sFieldContent -- it = sFieldContent
      filter it with "*" & the text of fld "fSearch" & "*"
      put it into sMyFoundContent
      put sMyFoundContent into field "fMyFoundContent"
   end if
end textchanged
Best regards
Jean-Marc

williamsc84
Posts: 7
Joined: Sun Aug 06, 2017 1:54 pm

Re: Clearing Search

Post by williamsc84 » Sun Aug 06, 2017 11:25 pm

Thank you Jean Marc for taking the time to not only provide me with the answer but help me understand how it works.

I have now implemented this and it works perfectly.

Thanks again for your detailed response, it's very much appreciated.

Steven

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2588
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Clearing Search

Post by jmburnod » Mon Aug 07, 2017 12:06 am

Hi Steven,
help me understand how it works
8)
I'am very proud that you understand my"lemanic's english" explanations.
I said "Names of controls make development too easy" without explanations.
Choosing a relevant name for controls and handlers is very helpful for development, update etc.. but also for your brain.
Best regards
Jean-Marc

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”