Allow FormLabel position to be defined in a configuration array #2542

Closed
zfbot opened this Issue Sep 28, 2012 · 9 comments

4 participants

@zfbot

Jira Information

Original Issue: ZF2-498
Issue Type: Improvement
Reporter: texdc
Created: 08/23/12
Assignee: weierophinney
Components: Zend\Form

Description

Currently, there is no way to define the position of FormLabels when elements are rendered in a collection or row. This is particularly relevant to checkbox, multiCheckbox and radio fields. By default, checkbox, multiCheckbox, and radio elements should append their label. Regardless, a '{{label_position}}' configuration option should be available and recognized by the FormCollection and FormRow helpers.

// inside Controller ...
$form->add(array(
   "name" => "remember",
   "type" => "Zend\Form\Element\Checkbox",
   "options" => array(
      "label" => "Remember Me",
      "label_position" => "append",
   ),
));
@zfbot

(Originally posted by: Michael Gallego on 09/05/12)

This is a good idea. I'll make a fix tomorrow for that.

EDIT : the only problem I can see is that this thing is relative to FormRow helper, so this means we are going to introduce something into the base Element that is used only by the FormRow helper. I'll talk to Matthew and cgmartin about that :).

@zfbot

(Originally posted by: cgmartin on 09/05/12)

We already have the label attributes attached to the base Element, so makes sense to me to be able to set label options on it as well.

Would it also be helpful to attach the FormElementError attributes (and options?) to the base Element? We run into the same kinds of limitations with rendering the errors as we do with the labels, in the context of FormRow.

@zfbot

(Originally posted by: texdc on 09/05/12)

My main goals for this in every context are:
1. Default (appended) rendering with no configuration for radio/checkbox elements
2. Custom rendering via configuration

I also agree with Chris' suggestion regarding errors.

The bottom line is that these elements should not be handled like other inputs when rendered.

@zfbot

This issue was ported from the ZF2 Jira Issue Tracker at
http://framework.zend.com/issues/browse/ZF2-498

Known GitHub users mentioned in the original message or comment:
@texdc, @weierophinney, @cgmartin

@ThaDafinser

@texdc @cgmartin this shouldn't be done in the configuration...IMO

For this are views and their helpers around.

If someone wants the labeled positioned every time somewhere else -> this should be done in their own view helper.

Can this get closed?

@texdc
@ThaDafinser

@texdc "jiein" (german: yes/no)...it depends.

You can also use label view helpers to accomplish this.
See here: http://framework.zend.com/manual/2.0/en/modules/zend.form.view.helpers.html#formlabel

I think it's difficult to draw here the line...What if you want to custom display the error messages and so on....should this be also part of the element declaration?

//Sidenote:
In ZF1 i also used a lot of direct complete form rendering, and in ZF2 i started to use view scripts and formRow and i couldn't be happier because the forms are now much better for the user...

@weierophinney
Zend Framework member

The more flags and switches:

  • The more difficult it is to consume the component (more to learn, more to know)
  • The more difficult it is to maintain the component (more potential breakage for any new functionality or fixes)

I think we actually provide too much functionality in the various form view helpers; they should be used as a base or an example, with developers writing application-specific or css-framework-specific helpers.

@texdc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment