show/hide fields of schema depending on previous fields input

2 Messages Forum Options Options
Embed this topic
Permalink
Rhonda Shirah
show/hide fields of schema depending on previous fields input
Reply Threaded More
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Message
I would like to show or hide certain fields of my schema depending on what the user chooses for the previous field.  I think I read somewhere that I can do this with a simple python definition call within the schema itself.  Problem is I don't know where I read this.  Is this true? 
 
Can I do something like:
 
schema = BaseSchema + Schema (
 
StringField('marital_status',
                required=1,
                vocabulary=marital_status,
                widget=SelectionWidget(label="Marital Status"),

                ),
IntegerField('years_married',
                widget=IntegerWidget(label="Number of Years Married"),
                visible={'view': python: isMarried(): 'visible'},
                )
)
 
def isMarried()
   if marital_status = "Married"
             return true
  else
            return false
 
 
 
Basically, if someone enters "Married" for marital_status, then isMarried() would return true and years_married field would appear.  I'm not sure of the exact syntax for the python call in the schema section.  Am I on the right track? 
 
Thanks,
Rhonda
 
Alec Mitchell
Re: show/hide fields of schema depending on previous fields input
Reply Threaded More
Print post
Permalink
On Thursday 03 November 2005 07:58 am, Rhonda Shirah wrote:

> I would like to show or hide certain fields of my schema depending on what
> the user chooses for the previous field.  I think I read somewhere that I
> can do this with a simple python definition call within the schema itself.
> Problem is I don't know where I read this.  Is this true?
>
> Can I do something like:
>
> schema = BaseSchema + Schema (
>
> StringField('marital_status',
>                 required=1,
>                 vocabulary=marital_status,
>                 widget=SelectionWidget(label="Marital Status"),
>                 ),
> IntegerField('years_married',
>                 widget=IntegerWidget(label="Number of Years Married"),
>                 visible={'view': python: isMarried(): 'visible'},
>                 )
> )
>
> def isMarried()
>    if marital_status = "Married"
>              return true
>   else
>             return false
>
>
>
> Basically, if someone enters "Married" for marital_status, then isMarried()
> would return true and years_married field would appear.  I'm not sure of
> the exact syntax for the python call in the schema section.  Am I on the
> right track?

What you want is

                widget=IntegerWidget(label="Number of Years Married",
                                     condition="object/isMarried")

however this will not cause the widget to appear and disappear dynamically.  
That would require javascript.  Another option to assign your IntegerField to
another schemata, then it will by on a later edit page, and will only appear
if the condition is met.  If you want the fields on the same page and you
want the visibility of one to depend on the value entered in another, then
look at MasterSelectWidget (http://plone.org/products/masterselectwidget)
which was designed for this purpose among other things.

Alec


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Plone-Users mailing list
Plone-Users@...
https://lists.sourceforge.net/lists/listinfo/plone-users