Search code examples
textareazend-formzend-framework3

How to make Textarea not resizable in Zend Form


I have a Zend Form and one of it's fields is a Textarea. I have set it's default size using 'rows' and 'cols' but I want the user not to be able to change it.

I have tried adding 'resize' => false, but it did not work.

public function __construct()
{
    parent::__construct('form');
    $this->setAttribute('method', 'post');
    $this->setAttribute('role', 'form');

    $this->add([
        'name' => 'feedback',
        'type' => Textarea::class,
        'attributes' => [
            'id' => 'feedback',
            'class' => 'mdc-text-field__input',
            'rows' => 3,
            'cols' => 4,
            'required' => false,
        ],
        'options' => [
            'label' => 'Feedback',
        ],
    ]);
}

Solution

  • You have the choice between

    attributes => [
        ...,
        'style' => 'resize:none'
    ]
    

    or use a css class

    attributes => [
        ...,
        'class' => 'notresizable'
    ]
    

    and define this css class in your css file.