[How To] Show fields based on options

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

Post Reply
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

[How To] Show fields based on options

Post by palanolho » Thu Jun 12, 2014 8:00 pm

Hi everyone,


On my application, I have a stack that will work as a options dialog.
On this stack I have several fields, but some of the fields should be different based on the value of a option button (one of the fixed fields).

EX:
--------------------
Field AA
Field BB
Option Button = 1
>> Field CC
>> Field DD
--------------------
Field AA
Field BB
Option Button = 2
>> Field EE
>> Field FF
--------------------

Anyone has any suggestion on what would be the best way to do this?

Many thanks in advance,
- Miguel

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

Re: [How To] Show fields based on options

Post by dunbarx » Thu Jun 12, 2014 8:28 pm

Hi.

On a new card drag over a new option menu. Put this into its script:

Code: Select all

on menuPick pItemName
   answer the menuHistory of me
end menuPick

on menuPick pItemName
   answer "Number" && menuHistory of me
end menuPick

on menuPick pItemName
   switch pItemName
      case "choice 1"
         answer "Number 1"
         break
      case "choice 2"
         answer "Number 2"
         break
   end switch
end menuPick

on menuPick pItemName
   switch pItemName
      case "choice 1"
      case "choice 2"
         answer pItemName
   end switch
end menuPick
Comment out one or the other. This gives you several ways (there are others) to think about how to make the users selection do what you want. Do you need help translating the results of the menu selection to your own task?

Craig Newman

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: [How To] Show fields based on options

Post by palanolho » Thu Jun 12, 2014 9:13 pm

OK maybe I did not explain correctly.

I know how to check for changes on the option button and based on that, execute something.

My question was regarding the fields that should be visible / hidden.

The idea is that the fields will be displayed on the same place (so no empty areas when ones disappear and the others become visible)

Should I implement this with different cards? with groups and changing the group content?
You know what I mean?

thanks

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

Re: [How To] Show fields based on options

Post by dunbarx » Thu Jun 12, 2014 10:14 pm

Hi again.

So if you have two fields with the same rect and at the same loc, what is wrong with simply showing one and hiding the other on the same card? I wonder if there would be a noticeable glitch if you do that. But you can always lock and unlock the screen. Are there visual effects involved?

If the fields to be shown and hidden are always the same, you can group them to simplify the process. Otherwise you can "group" then by some property, to identify them as you cycle through whatever process you use to show/hide.

I still suspect that I am not understanding, since I bet you knew all of what I just said already as well.

Craig

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: [How To] Show fields based on options

Post by palanolho » Fri Jun 13, 2014 8:35 am

Lets see if an image helps :)

Imagine a stake like this, where the field OPTION (in red) define which fields are visible below it:

Image

Is it clearer now ?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: [How To] Show fields based on options

Post by Simon » Fri Jun 13, 2014 8:55 am

Hi Miguel,
Yeah, that looks like hide/show group.
2014-06-13_0053.png
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: [How To] Show fields based on options

Post by palanolho » Fri Jun 13, 2014 8:57 am

Okidoky

thanks :)

Post Reply