jeudi 3 mars 2016

How to set checkbox label position without using formMultiCheckbox(...) in ZF2?

I want to be able to set the label position:

  • for the entire element and
  • (in case of checkboxes / radio buttons) additionally for every single checkbox / radio button.

I have a form, that is build like this:

<?php
$form = $this->form;
$form->setAttribute('action', $this->url());
$form->prepare();

echo $this->form()->openTag($form);
?>

<?php $fooFieldset = $form->get('foo'); ?>

<div id="fieldset-foo" class="fieldset-container col-md-6">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title"><?php echo $this->translate($fooFieldset->getLabel()); ?></h3>
        </div>
        <div class="panel-body">
            <?php foreach ($fooFieldset as $element) : ?>
            <div class="form-group <?php if($this->formElementErrors($element)) echo 'error' ?>">
                <?php $element->setOption('label_position', FormRow::LABEL_PREPEND); /* not working! */ ?>
                <label><?php echo $this->translate($element->getLabel()); ?></label>
                <div>
                    <?php $element->setAttribute('class', 'form-control'); ?>
                    <?php echo $this->formElement($element); ?>
                    <?php if ($this->formElementErrors($element)) : ?>
                        <div class="message-error"><?php echo $this->formElementErrors($element) ?></div>
                    <?php endif; ?>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
</div>

<!-- futher fieldsets -->

<!-- fields without fieldsets -->


<?php
echo $this->form()->closeTag($form);
?>

That means, I'm not calling the formRow(...) or formMultiCheckbox(...) and cannot configure the label_position on this way. The setting an option directly on the element ($element->setOption('label_position', FormRow::LABEL_PREPEND)) does not work at all -- neither for the entire element nor for checkboxes / radio buttons.

How to get it working and set the label position (1. for the entire element; 2. for the checkboxes / radio buttons) here?




Aucun commentaire:

Enregistrer un commentaire