Dropdown/Option menu embedded in text in field

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 457
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Dropdown/Option menu embedded in text in field

Post by kaveh1000 » Sun Feb 21, 2021 3:05 pm

Hi all

Sorry for over a year of absence!

I have a requirement for some "variable" text within a field. It is to replace the usual "mail merge" function where a variable is put in between special characters, e.g.

%FIRST_NAME%

I am trying to make that more user friendly, so a user can select a choice from a pop-up menu. Then behind the scenes a text is generated with the correct codes embedded, e.g. %FIRST_NAME%, %SURNAME%. Please see screenshot of the idea.

What is the best approach to achieve this in LiveCode? I am sure there will be an elegant way! I thought of imagesource, but I want to embed a live menu if possible.

The next stage after this will be to implement this in HTML. I have no idea what the limitations are there. But I want to create this "prototype" first...

Regards
Kaveh
Attachments
Screenshot 2021-02-21 at 14.01.36.png
Kaveh

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5384
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Dropdown/Option menu embedded in text in field

Post by richmond62 » Sun Feb 21, 2021 3:17 pm

Screenshot 2021-02-21 at 16.16.17.png
-
Erm, well, at least it's a start. 8)

bogs
Posts: 5097
Joined: Sat Feb 25, 2017 10:45 pm

Re: Dropdown/Option menu embedded in text in field

Post by bogs » Sun Feb 21, 2021 3:44 pm

I *think* your looking for something like this -
Image

Make sure the field the text is in is locked, the transversal can be off or not. The button's "visible" is set to false, the menu will pop up at the location of the mouseLoc without needing to code it specifically. Of course, if you want the menu to overlay the word clicked on, its location can be changed ;)

In your case, you would have to add a menuPick handler as well, most likely.
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7405
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Dropdown/Option menu embedded in text in field

Post by dunbarx » Sun Feb 21, 2021 5:12 pm

Hi

Try this:
kaveh.livecode.zip
(9.22 KiB) Downloaded 10 times
Craig

bogs
Posts: 5097
Joined: Sat Feb 25, 2017 10:45 pm

Re: Dropdown/Option menu embedded in text in field

Post by bogs » Sun Feb 21, 2021 5:39 pm

I'm not kaveh, but I tried it. It was both interesting and confusing heh heh.
Image

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 457
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Dropdown/Option menu embedded in text in field

Post by kaveh1000 » Sun Feb 21, 2021 5:42 pm

Thanks to all.

@Richmond – I did not know about linkClicked. Thanks for that

@Bogs - That seems to be the closest approach I need to take. Please note:
  • I need the text to be editable too, so thinking that when the mouse is over the target text, or when cursor in in target text I lock text. Else I unlock it
  • I need the replacement text to be visible, so when I select "Surname", then that text should show instead of [link]. Thinking of having a backgroundcolor for target text, so text can change but I know it is the variable text
@Craig - I need the variable text elements to behave as text, in that they move around and wrap as the text is edited. Imagine you have to edit the text, and also select what variable text goes in between the words.

I am going to work on this and report back. Thanks as always...

Regards
Kaveh
Kaveh

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7405
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Dropdown/Option menu embedded in text in field

Post by dunbarx » Sun Feb 21, 2021 6:00 pm

- I need the variable text elements to behave as text, in that they move around and wrap as the text is edited. Imag
So, instead of dumping the clickText into a field, which I did just for show, would appending the selection right after the clickChunk do?

I originally made this with a pullDown, but did not like the fact that the actual button was displayed along with the menuItems. Now it occurs to me that I could have set the blendLevel to hide the "button" portion, thus only displaying the menuItems.

Craig

Klaus
Posts: 12204
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Dropdown/Option menu embedded in text in field

Post by Klaus » Sun Feb 21, 2021 6:26 pm

Hi Kaveh,

I case you didn't know, LC also has a MERGE() function which uses -> [[xxx]] for placeholders.
Field "text with placeholders":
-----------------------------------
Lorem ipsum dolor sit amet, [[first_name]] [[tName]] elitr, sed ...
-----------------------------------
Resolve:

Code: Select all

...
put "Willie" into first_name
put "Wonka" into tNname
put merge(fld "text with placeholders") into fld 2
...
Field 2:
-------------------------------------
Lorem ipsum dolor sit amet, Willie Wonka elitr, sed ...
-------------------------------------
You can also use functions as placeholder and expressions -
-> [[fld "addition1" + fld "addition2"]]
-> [[the label of btn "a button" of cd 56 of stack "another stack"]]
-> [[mycomplicatedfunction(fld "some values")]]
etc.
You get the picture.


Best

Klaus

bogs
Posts: 5097
Joined: Sat Feb 25, 2017 10:45 pm

Re: Dropdown/Option menu embedded in text in field

Post by bogs » Sun Feb 21, 2021 8:10 pm

kaveh1000 wrote:
Sun Feb 21, 2021 5:42 pm
@Bogs - That seems to be the closest approach I need to take.
I dunno, what Klaus put is a LOT more interesting heh.
Image

Klaus
Posts: 12204
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Dropdown/Option menu embedded in text in field

Post by Klaus » Sun Feb 21, 2021 10:22 pm

bogs wrote:
Sun Feb 21, 2021 8:10 pm
...
I dunno, what Klaus put is a LOT more interesting heh.
:D :D :D

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 457
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Dropdown/Option menu embedded in text in field

Post by kaveh1000 » Sun Feb 21, 2021 10:49 pm

I had no idea of merge() either! Thanks Klaus. My first problem to get the interface sorted, and I am slowly working on that. But good to know easy to merge after and I don't have to use regex.

Unfortunately this has to be reimplemented using PHP and other web tools. I have no idea if that can be done but if I make a prototype it will push my colleagues to find a way...
Kaveh

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”