[Grok-dev] Dependent choice fields with formlib

Sebastian Ware sebastian at urbantalk.se
Fri Sep 19 03:26:35 EDT 2008


It should work, maybe a typo?

With Choice fields you have a choice to select one of the items in the  
vocabulary. If you want other behaviour you can create your own custom  
field type. There is a discussion regarding that in zope.schema /  
fields.txt.

I am curious, if your choice field "slave" is updated with regards to  
"master", why don't you use a vocabulary to allow context sensitive  
generation of options for "slave"? I must be misunderstanding your  
problem, because it looks pretty straight forward to me.

1 Generate a list of countries for master
2 Use a vocabulary to generate a list of options for slave
   - based on what is stored for "master"
   - adding any preselected content for "slave" to the list
     or changing the content of "slave" in the update method

Mvh Sebastian

19 sep 2008 kl. 01.04 skrev Santiago Videla:

> Hi Sebastian
>
> I don't get it
>
> Why should works that? looking at the code, I understand that choice  
> fields always run the _validate() function before any custom  
> validate, constraint or invariant. And that function, raise an  
> exception if the selected value is not in the initial vocabulary.
>
> Anyways, I added the default value, but nothing changed
>
> cheers
>
> On Thu, Sep 18, 2008 at 1:53 PM, Sebastian Ware <sebastian at urbantalk.se 
> > wrote:
> I am guessing here, but I think you can add a
>
>  default="xyz"
>
> to your choice field, and then allways have an item in values that  
> corresponds to xyz (such as "Select one...")
>
> Mvh Sebastian
>
> 18 sep 2008 kl. 17.07 skrev Santiago Videla:
>
> Hi,
>
> I'm trying to make a custom search form using formlib
>
> In that form I have 1 select (schema.choice) that depends on another  
> select field, and using KSS when one changes the other is updated  
> (for example, country and city)
>
> My interface is something like this
>
>   master = schema.Choice(title='Master field',  
> vocabulary='some.registered.vocabulary')
>   slave = schema.Choice(title='Slave field', values=['Select  
> one...',])
>
> But when the slave field it's update using KSS, the submit action  
> give me an "Invalid Input" error in the slave field.
>
> I guess that this is because, the values updated does not belong to  
> the list of values (['Select one...'])
>
> How should I tackle this?
>
> thanks in advance
>
>
> -- 
> Santiago Videla
> www.revolucionesweb.com.ar
> http://www.linkedin.com/in/svidela
>
> Sigue la mata dando de que hablar siempre abajo y a la izquierda  
> donde el pensamiento que se hace corazón resplandece con la palabra  
> sencilla y humilde que l at s tod at s somos.
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
>
>
>
>
> -- 
> Santiago Videla
> www.revolucionesweb.com.ar
> http://www.linkedin.com/in/svidela
>
> Sigue la mata dando de que hablar siempre abajo y a la izquierda  
> donde el pensamiento que se hace corazón resplandece con la palabra  
> sencilla y humilde que l at s tod at s somos.



More information about the Grok-dev mailing list