How to put a list into a field on a card

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

Post Reply
trags3
Posts: 425
Joined: Wed Apr 09, 2014 1:58 am

How to put a list into a field on a card

Post by trags3 » Tue Jan 28, 2025 9:38 pm

I have a .txt file that is a list of items.
I want to put this list into a field on a card when the card is opened and as characters are typed into a search field only items in the .txt file that match are shown.
What I mean is that If the first character I type in is a "P" then only lines beginning with "P" are displayed in the List. Then if I type in an "o" only items beginning with "Po" are displayed.
I know this can be done but I don't know how.
Thanks
Tom

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4140
Joined: Sun Jan 07, 2007 9:12 pm

Re: How to put a list into a field on a card

Post by bn » Wed Jan 29, 2025 9:57 am

Hi Tom,

Here is a stack that shows one way to do this. It uses the "colorNames" as an example.
It uses a display field "fList" for the filtered list and the whole list is stored as a custom property of that field.
Instead of a custom property you could use any other container to store the complete list that is filtered into the list field.

Kind regards
Bernd
Attachments
filterList.livecode.zip
(4.97 KiB) Downloaded 26 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9864
Joined: Fri Feb 19, 2010 10:17 am

Re: How to put a list into a field on a card

Post by richmond62 » Wed Jan 29, 2025 12:10 pm

Screenshot 2025-01-29 at 13.09.09.png
Attachments
DaftList.txt.zip
Sample text File
(653 Bytes) Downloaded 25 times
Filtration.livecode.zip
Stack
(1.43 KiB) Downloaded 18 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9864
Joined: Fri Feb 19, 2010 10:17 am

Re: How to put a list into a field on a card

Post by richmond62 » Wed Jan 29, 2025 1:24 pm

I apologise unreservedly for spelling 'Piccalilli' wrongly:

https://en.wikipedia.org/wiki/Piccalilli

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4140
Joined: Sun Jan 07, 2007 9:12 pm

Re: How to put a list into a field on a card

Post by bn » Wed Jan 29, 2025 1:33 pm

richmond62 wrote:
Wed Jan 29, 2025 1:24 pm
I apologise unreservedly for spelling 'Piccalilli' wrongly:
https://en.wikipedia.org/wiki/Piccalilli
Hi Richmond,
Thank you for making me aware of Piccalilli.

How about setting the script of field "Sieve" to

Code: Select all

on textChanged
   local tWholeText, tfilteredText
   put field "fGUFF" into tWholeText
   filter lines of tWholeText with the text of me & "*"
   put tWholeText into field "fFILTER"
end textChanged
?

Kind regards
Bernd

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9864
Joined: Fri Feb 19, 2010 10:17 am

Re: How to put a list into a field on a card

Post by richmond62 » Wed Jan 29, 2025 1:56 pm

Super Bernd.

But then I have always been the man who uses a SHOVEL to stir the sugar in his coffee, while you are the man with the refined silver spoon. :P

trags3
Posts: 425
Joined: Wed Apr 09, 2014 1:58 am

Re: How to put a list into a field on a card

Post by trags3 » Mon Feb 03, 2025 2:30 am

Hi Bernd and Richmond!
I appreciate your help, but I've not been able to make this work quite yet.
The problem I have is I have a text file with About 300 Items. One line per Item.
I need to load that file into a field where the user can then search for a particular
Item. The problem I have Is on fairly rare occasions each user of the app will need to
add one or more items to the list. I have included that ability in the App I have written.
I don't quite understand where the data in Bernd's example comes from, and I
don't want the user to be required to select a file in order to use it in Richmond's
example. I hope this is clear. I have been away from LC for a couple of years and am
a little rusty.
Thanks in advance for your help. I really do appreciate it.

Tom

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

Re: How to put a list into a field on a card

Post by dunbarx » Mon Feb 03, 2025 4:30 am

The problem I have Is on fairly rare occasions each user of the app will need to
add one or more items to the list.
If I understand your last post, assuming the field is locked, simply put this into its script:

Code: Select all

on mouseUp
   put the text of me into origText
   ask "enter new data"
   if it <> "" and the result <> "Cancel" then
      put return & it after origText
      sort origText
      put origText into me
   end if
end mouseUp
Craig
Last edited by dunbarx on Mon Feb 03, 2025 3:11 pm, edited 1 time in total.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4140
Joined: Sun Jan 07, 2007 9:12 pm

Re: How to put a list into a field on a card

Post by bn » Mon Feb 03, 2025 11:36 am

Hi Tom,

I tried to adapt my stack to your specs.
It uses 2 fields: one is the complete list of entries that should probably be out of view. That list of entries is used to display the entries or the filtered entries.
I currently use the ColorNames to give the list some 500 entries to work with and see how it responds.

I added the option to add an entry to the complete list.

Clicking on the display list triggers a script for an action when the user clicks at the field, currently it displays the text of the clicked line.

See if it works for you.

Kind regards
Bernd
Attachments
filterList2.livecode.zip
(3.76 KiB) Downloaded 9 times

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”