From: Christian Weiske on
Hello Alexey,


I am trying to use HTML_QuickForm2_Renderer_Array to build form with a
pretty customized layout. Now I wanted to put the element html in the
template but failed a bit because the elements array is indexed with
numbers - but in my template, I don't want to iterate over the elements
array to look for the one with the correct ID.
Why did you use a number as key and not the element ID?

--
Regards/Mit freundlichen Grüßen
Christian Weiske

-=≡ Geeking around in the name of science since 1982 ≡=-
From: Alexey Borzov on
Hi Christian,

On 03.05.2010 22:56, Christian Weiske wrote:
> I am trying to use HTML_QuickForm2_Renderer_Array to build form with a
> pretty customized layout. Now I wanted to put the element html in the
> template but failed a bit because the elements array is indexed with
> numbers - but in my template, I don't want to iterate over the elements
> array to look for the one with the correct ID.
> Why did you use a number as key and not the element ID?

Well, Array renderer is mostly a direct port of Array renderer from QuickForm
3.x, which is used in iteration scenario (see its example in QF 3.x).

ArraySmarty renderer that uses element names as keys was not ported, Alain
Williams tried implementing that but didn't get it to proposal stage for some
reason, you can try contacting him.

Also you don't actually need a renderer in Quickform2 as much, you can just call
echo $form->getElementById('elementId');
in strategic places or do the equivalent of that in the template engine of you
choice.
From: Alexey Borzov on
Hi Christian,

On 26.05.2010 21:27, Christian Weiske wrote:
>>> I am trying to use HTML_QuickForm2_Renderer_Array to build form
>>> with a pretty customized layout. Now I wanted to put the element
>>> html in the template but failed a bit because the elements array
>>> is indexed with numbers - but in my template, I don't want to
>>> iterate over the elements array to look for the one with the
>>> correct ID. Why did you use a number as key and not the element ID?
>>
>> Well, Array renderer is mostly a direct port of Array renderer from
>> QuickForm 3.x, which is used in iteration scenario (see its example
>> in QF 3.x).
>>
>> ArraySmarty renderer that uses element names as keys was not ported,
>> Alain Williams tried implementing that but didn't get it to proposal
>> stage for some reason, you can try contacting him.
>>
>> Also you don't actually need a renderer in Quickform2 as much, you
>> can just call echo $form->getElementById('elementId');
>> in strategic places or do the equivalent of that in the template
>> engine of you choice.
>
> Is there any benefit of having a numerically indexed array returned by
> toArray()? I mean this is QF2, breaking BC with QF is fine, and using
> element ids as array index is definitely something we should get.
>

Well, as I already said, Array renderer was designed to be used in iteration
scenario. There isn't much added value with released QF2 over iterating on
QuickForm2 object directly, but right now I'm working on client-side validation
and that is generated on rendering pass.

There definitely is a need for Array renderer that will return an array indexed
by element IDs. I just don't want to make it the only available Array renderer.
From: Alexey Borzov on
Hi Christian,

On 27.05.2010 12:23, Christian Weiske wrote:
>> There isn't much added value with released QF2
>> over iterating on QuickForm2 object directly,
> Could you explain that? I don't understand the sentence :/

Sorry, I should have been more verbose.

Iterating over array returned by Array renderer
$ary = $form->render(HTML_QuickForm2_Renderer::factory('array'))->toArray();
foreach ($ary as $elAry) {
echo $elAry['html'] . '<br />';
}

Iterating over HTML_QuickForm2 instance directly:
foreach ($form as $element) {
echo $element->__toString() . '<br />';
}