[Zope] Selection Box

Steen Suder sfs@kollegie6400.dk
Tue, 19 Oct 1999 09:03:49 GMT


> On Tue, Oct 19, 1999, John Glossner wrote:
> 
> > I have searched most reference material with no avail to try 
> > to find out how to set up a simple selection box.
> > 
> > I have a ZClass called LinkClassification to which I have attached
> > a property link_class which is assigned to value link_class_data.
> > 
> > My question is where do I create the variable link_class_data?
> > I think it should be as another property in the same directory.
> > When I do this the zope management screen hangs.
> 
> link_class_data must be in the appropriate namespace to be visible
> to the propertysheet. 
> 
>  1. Define it as a "lines" Property
> 
>  2. Define it as a method that returns an array of items, ie:
> 	<dtml-return "('Option 1','Option 2')">
> 
>  3. Define it as a TinyTable, with one column name: "sequence-item"
> 
> If you add these lists to the Product containing your ZClass, then
> the propertysheet for an instanciated object of the ZClass will
> give you errors when it shows up.
> 
> So you copy the lists inside of your ZClass definition. The
> downside is apparent: every object now has a copy of all of your
> lists. Big bummer when it comes to long lists of items or a 
> large number of objects.
> 
> But, the real problem comes when you try to create an instance
> of your ZClass outside of the management UI. This is a battle
> that I'm still loosing (even using KMnetNews as an example). :(
> 
> > I presume this is because I did not define the link_class_data
> > property correctly. What are the valid types allowed for
> > a selection box - strings,text,etc.?
> 
> It must be a list.
>  - more importantly: it must be a list that implements
>    sequence-item when iterated through (if you use a 
>    TinyTable without naming your column as "sequence-item",
>    you get odd results :)
> 
> It must be in a variable (it can't be an expression).
>  - this breaks using objectValues() or something similar
> 
> It must be relative (you cannot fully qualify it "with.a.path").
>  - this breaks "globalizing" lists into a Product namespace
> 
> > Does someone have the syntax for how the selection box is
> > assigned a variable? Or is there an example somewhere I 
> > can reference?
> 
> This is the real pain. In order to draw a selection box that
> has a specific variable selected, you need to have a massive
> hunk 'o code in a loop to compare every option to the selected
> value. If a value is selected, then you put the "SELECTED"
> keyword in the OPTION tag. ARGH.

Perhaps I do not understand your intentions correctly, but here is my take
on the issue.

It sounds like you need the <!--#in "sequence-object"--> tag...

Example (feed a SELECT from SQL, but it's the same thing...):

<SELECT name="category">
<!--#in db_get_cats_qry-->
  <dtml-if "category == link_cat_id">

    <OPTION SELECTED VALUE='<dtml-var link_cat_id null="">'><dtml-var
cat_text null="">

  <dtml-else>

    <OPTION VALUE='<dtml-var link_cat_id null="">'><dtml-var cat_text
null="">

  </dtml-if>
<!--#/in-->


The example is simplified slightly.
Category is SQL method, cat_text is coloumn from the query, containing a
description and link_cat_id is the "key" from th query.

As I understand it, a ZSQL method just returns a 'sequence-object', thus it
can be just about anything.

I think this is quite simple: 2 x SELECT tags, 2 x in tags and 3 x if tags,
equals 7 lines to handle the SELECT and the SELECTED state of an OPTION.

> There has to be an easier way. I'm beginning to think that
> a "Utils" folder with common "tag renderers" would be alot
> easier than the mess I've been stumbling through for the past
> 3 days.
> 
> DTML is difficult. Coding ZClasses purely in DTML is a nasty
> experience if you want to do anything useful with the
> resulting objects outside of the management interface.

I don't agree; it's just another way of doing things... and I'm not a coder
;-)

<CUT>

-- 
Best regards / mvh.,
Steen Suder
sysadm kollegie6400.dk
OpenSource - Sign of the time