Custom textarea's in panel

Hi all,

I was wondering how I could change the HTML of the textareas in the panel.
I do know that I can make custom form fields. But I don’t know how to change the HTML of for example the textareas. What I did was copying the default textarea. How can I change the html of this? Maybe adding a class would be enough

What do you want to achieve?

If you only want to add. a class, you can. add it in the input() method of your textarea copy (textarea.php):

  public function input() {

    $input = parent::input();
    $input->tag('textarea');
    $input->removeAttr('type');
    $input->removeAttr('value');
    $input->addClass('someclass'); // add class here
    $input->html($this->value() ? htmlentities($this->value(), ENT_NOQUOTES, 'UTF-8') : false);
    $input->data('field', 'editor');

    return $input;

  }

But maybe adding a custom stylesheet is enough?

Okay I see, thanks for that.

And I also see that there is an element that wraps the input (it has an $element variable). Would I be able to change the HTML of this element? For instance add a <h2> or perhaps even an <img> tag in it?

The you would have to modify in the element(). method, for example:

  public function element() {

    $element = parent::element();
    $element->addClass('field-with-textarea');

    if($this->buttons and !$this->readonly) {
      $element->addClass('field-with-buttons');
    }
    $headline = new Brick('h2',  'Some headline'); // create a new h2 element
    $element->append($headline); // append to the element
    return $element;

  }

Still interested in learning what your use case is…

Alright, thanks. And is there also some kind of wrap function? So for example I want to wrap the element in another DIV?

Yes, you can do all that, instead of calling the parent, you can create your own wrapper and totally modify. it. Check out the source code. and that. of the. parent class how it works.