Zend decorator - Add css class on field element?

Seb33300

I am trying to use a zend decorator to use custom containers and add css classes on my elements.

$form->setElementDecorators(array(
    'viewHelper',
    'Errors',
    array('Label'),
    array(
        array('row'=>'HtmlTag'),
        array('tag'=>'div', 'class'=>'col-md-6')
    )
));
$form->setDecorators(array(
    'FormElements',
    array(
        array('data'=>'HtmlTag'),
        array('tag'=>'div', 'class'=>'row')
    ),
    'Form'
));

Is there a way to add a css class directly on my inputs? <input class="form-control">

Is there a way to encapsulate label and input in 2 divs?

Actually i have is

<div class="col-md-6">
    <label></label>
    <input>
</div>

and what i wish is

<div class="col-md-6">
    <div class="form-group">
        <label></label>
        <input class="form-control">
    </div>
</div>

Also where can i found documentation about array to pass to setElementDecorators() function?

Thanks

doydoy44

Try to add HtmlTag decorator like this:

$form->setElementDecorators(array(
    'viewHelper',
    'Errors',
    array('Label'),
    array(
        array('row'=>'HtmlTag'),
        array('tag'=>'div', 'class'=>'form-group'),        
    ),
    array('HtmlTag', array('tag'=>'div', 'class'=>'col-md-6')),
));

For all elements, you can add a class like this:

Example to set form-control class:

foreach($form->getElements() as $element){
    $element->setAttrib('class', 'form-control');
}

Example to add form-control class:

foreach($form->getElements() as $element){
    $element->setAttrib('class', 'form-control' . ($element->getAttrib('class') == '' ? '' :  ' ' . $element->getAttrib('class')));
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Add a css class to a field in wtform

From Dev

How to add class and id to form element in Zend Framework 2.2.4

From Dev

How to add class and id to form element in Zend Framework 2.2.4

From Dev

How to add a class to an element with CSS

From Dev

css add class to selected element

From Dev

Add class attribute with decorator

From Dev

Add css class to all admin form field

From Dev

How to add an image to an element as a decorator?

From Dev

How to add CSS class dynamically to html element

From Dev

Javascript - add css style to element with class

From Dev

Want to add a CSS class to an element when it is clicked

From Dev

How to add | remove css class in angular element?

From Dev

How to add css class to an element inside nav element

From Dev

Add a css class to an element if the element has a certain text via javascript

From Dev

Class decorator - modification of class field changes value in base class too

From Dev

Silverstripe 3 - add css class to CMS form field

From Dev

Yii2 - How To Add a CSS class to an ActiveForm Field

From Dev

How to add CSS class to password field using jquery in MVC?

From Dev

How to add CSS class to password field using jquery in MVC?

From Dev

Silverstripe 3 - add css class to CMS form field

From Dev

Dynamicaly add methods from outside the class with a decorator

From Dev

Add a decorator to existing builtin class method in python

From Dev

Add a decorator to existing builtin class method in python

From Dev

How to add class CSS after ng-click to parent element?

From Dev

Adblock. Add css class or remove attribute from element

From Dev

Typo3 6.2 add a css class on a content element "image"

From Dev

How Do I Add CSS Class to body Element in Meteor?

From Dev

How to add CSS class to the HTML5 picture element

From Dev

Add css-class to primefaces datatable <table>-element

Related Related

  1. 1

    Add a css class to a field in wtform

  2. 2

    How to add class and id to form element in Zend Framework 2.2.4

  3. 3

    How to add class and id to form element in Zend Framework 2.2.4

  4. 4

    How to add a class to an element with CSS

  5. 5

    css add class to selected element

  6. 6

    Add class attribute with decorator

  7. 7

    Add css class to all admin form field

  8. 8

    How to add an image to an element as a decorator?

  9. 9

    How to add CSS class dynamically to html element

  10. 10

    Javascript - add css style to element with class

  11. 11

    Want to add a CSS class to an element when it is clicked

  12. 12

    How to add | remove css class in angular element?

  13. 13

    How to add css class to an element inside nav element

  14. 14

    Add a css class to an element if the element has a certain text via javascript

  15. 15

    Class decorator - modification of class field changes value in base class too

  16. 16

    Silverstripe 3 - add css class to CMS form field

  17. 17

    Yii2 - How To Add a CSS class to an ActiveForm Field

  18. 18

    How to add CSS class to password field using jquery in MVC?

  19. 19

    How to add CSS class to password field using jquery in MVC?

  20. 20

    Silverstripe 3 - add css class to CMS form field

  21. 21

    Dynamicaly add methods from outside the class with a decorator

  22. 22

    Add a decorator to existing builtin class method in python

  23. 23

    Add a decorator to existing builtin class method in python

  24. 24

    How to add class CSS after ng-click to parent element?

  25. 25

    Adblock. Add css class or remove attribute from element

  26. 26

    Typo3 6.2 add a css class on a content element "image"

  27. 27

    How Do I Add CSS Class to body Element in Meteor?

  28. 28

    How to add CSS class to the HTML5 picture element

  29. 29

    Add css-class to primefaces datatable <table>-element

HotTag

Archive