Skip to content

Instantly share code, notes, and snippets.

@sinamiandashti
Last active January 2, 2016 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinamiandashti/8313472 to your computer and use it in GitHub Desktop.
Save sinamiandashti/8313472 to your computer and use it in GitHub Desktop.
TWB bundle inline layout in fieldset issue
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'hostmacros',
'twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE,
'options' => array(
// 'label' => 'Please choose categories for this product',
// 'count' => 2,
'twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE,
'should_create_template' => true,
'allow_add' => true,
'target_element' => array(
'type' => 'NocConfig\Form\HostMacros',
),
),
));
<?php
namespace NocConfig\Form;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
class HostMacros extends Fieldset implements InputFilterProviderInterface
{
public function __construct()
{
parent::__construct('hostmacros');
$this->setHydrator(new ClassMethodsHydrator(false));
$this->setOptions(array('twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE));
$this->add(array(
'name' => 'macro',
'attributes' => array(
'placeholder' => "{\$MACRO}",
'name' => 'macros',
),
'options' => array(
'label' => ''
),
));
$this->add(array(
'name' => 'value',
'attributes' => array(
'placeholder' => "value",
'name' => 'value',
),
'options' => array(
'label' => ''
),
));
}
/**
* Should return an array specification compatible with
* {@link Zend\InputFilter\Factory::createInputFilter()}.
*
* @return array
*/
public function getInputFilterSpecification()
{
return array(
'macro' => array(
'required' => false,
),
'value' => array(
'required' => false,
),
);
}
}
<fieldset><fieldset><div class="form-group "><input name="hostmacros[0][macros]" placeholder="{$MACRO}" class="form-control" type="text" value=""></div>
<div class="form-group "><input name="hostmacros[0][value]" placeholder="value" class="form-control" type="text" value=""></div>
</fieldset><span data-template="&lt;fieldset &gt;&lt;div class=&quot;form-group &quot;&gt;&lt;input name=&quot;hostmacros[__index__][macros]&quot; placeholder=&quot;{$MACRO}&quot; class=&quot;form-control&quot; type=&quot;text&quot; value=&quot;&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;form-group &quot;&gt;&lt;input name=&quot;hostmacros[__index__][value]&quot; placeholder=&quot;value&quot; class=&quot;form-control&quot; type=&quot;text&quot; value=&quot;&quot;&gt;&lt;/div&gt;
&lt;/fieldset&gt;"></span></fieldset>
<? echo $this->formCollection($this->form->get('hostmacros'),true,'inline'); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment