durusmail: quixote-users: Help setting RadiobuttonsWidget options
Help setting RadiobuttonsWidget options
2004-12-27
2004-12-27
Help setting RadiobuttonsWidget options
mso@oz.net
2004-12-27
I have a form with two radio buttons like so:

    Match all words between fields (AND)
Match any words between fields (OR) .... so it submits as 'relation=and' (default) or 'relation=or'. widget.RadiobuttonsWidget takes an 'options' argument that's a list of (object, description, key). 'description' is the label next to the button. What I don't understand is, what do 'object' and 'key' mean, and how are they intended to be used? The following code produces the correct HTML: AND_OR = [ ("and", "Match all words between fields (AND)", "and"), ("or", "Match any words between fields (OR)", "or") ] form.add_radiobuttons('relation', title='Relation', options=AND_OR, delim=htmltext("
\n"), value="and") I expected this to work: AND_OR = [ ("and", "Match all words between fields (AND)"), ("or", "Match any words between fields (OR)") ] but it makes the value duplicate the label, and the first argument (which I thought was the value) is used only to see if the option is initially checked. I looked through the source to figure out what it's trying to do, and the superclass SelectWidget.set_options() parses the 'options' argument to fill in the missing second or third elements. It calls the first element 'object' in the docstring but 'value' in the code. To fill in the third element it calls SelectWidget._generate_keys(). This tries to extract an "oid" from the first element (assuming it's a ZODB node), and if that fails it duplicates the description. Which makes me wonder why is the third element ('key') turning into a value, what the first element is for, and how this relates to redisplaying the form if there's a user error? Currently I'm setting the value explicitly value="and" which is fine for a blank form but not right for a redisplayed form. Should I redisplay it as value = request.form['relation'] or should I be doing something with this 'object' element? -- Mike Orr
reply