Page 1 of 1

Clearing Search

Posted: Sun Aug 06, 2017 2:09 pm
by williamsc84
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

Re: Clearing Search

Posted: Sun Aug 06, 2017 2:48 pm
by shaosean
I think you need to empty out, or update, your sFieldContent variable

Re: Clearing Search

Posted: Sun Aug 06, 2017 3:13 pm
by jmburnod
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

Re: Clearing Search

Posted: Sun Aug 06, 2017 11:25 pm
by williamsc84
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

Re: Clearing Search

Posted: Mon Aug 07, 2017 12:06 am
by jmburnod
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