Re: Your opinion about QuickForm2 API

From: Date: Tue, 17 Apr 2007 07:58:12 +0000
Subject: Re: Your opinion about QuickForm2 API
References: 1 2  Groups: php.pear.dev php.pear.general 
Request: Send a blank email to pear-dev+get-46266@lists.php.net to get a copy of this message
Alexey Borzov schrieb: [...]
What's really being discussed is the following, will we make the "additional data" parameter that has different semantics from element to element always an array, so the first pair of calls above turns into $form->addElement('button', 'aButton', array('content' => 'Click me please')); $form->addElement('select', 'aSelect', array('options' => array('1' => 'option 1', '2' => 'option 2'))); even though the elements in question will never need any additional data other than 'content' and 'options'.
I assume it is more consistent to always use an array and provide additional setters for all possible keys, so every element can be added in both ways: $form->addElement('button', 'aButton', array('content' => 'Click me', 'attributes' => array('onClick' => 'alert("Clicked!")'))); or: $clickbutton = $form->addElement('button', 'aButton'); $clickbutton->setContent('Click me'); $clickbutton->setAttributes('onClick' => 'alert("Clicked!")'); Like this, every public property can actually be set on element construction. Anyway I see an other point I want to strongly advise to rethink: It looks like the QF2 API will still be quite near to the HTML syntax of every single element, which is actually not consistent across the elements and their natures. I gather this assumption from the "options" property of the select element (besides: setOptions() also confuses as this method has a totally different meaning in many other PEAR classes). If you put your focus at interchangability of elements, you find 2 different kinds of lists, which can both have 2 different forms: 1. List with only one element selectable: - Select element with size=1 (or no size attribute) - Radiobutton group 2. List with multiple selectable elements: - Select element with size > 1 - Checkbox group IMO those should be treated identically, for example: $ctry = $form->addElement('select', 'country'); $ctry->setList(array('CH' => 'Switzerland', 'FR' => 'France')); $ctry->setContent('CH'); If you later decide to change it to a radiogroup, you just have to change the line: $ctry = $form->addElement('radiogroup', 'country'); Also note that I suggest to use setContent() to define the preselected option rather than something like $option->setSelected() (which could be left as an alternative). It looks consistent to me to set the preselected value with the same method for all kinds of elements/groups, regardless of the way it looks in the generated HTML. So setContent() in a select box will result in setting the selected attribute, while it will set a value attribute if applied on a text field. -- Markus

« previous php.pear.dev (#46266) next »