Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust number of Rows to Form:: Textarea Laravel 5

How can I control the number of Rows added to a textarea using the Illuminate\Html\FormFacade class?

I have added the field into my template.

<div class="form-group">
  {!! Form::label('placeOfDeath','Place of Death') !!}
  {!! Form::textarea('placeOfDeath',null,['class'=>'form-control']) !!}
</div>

When it gets rendered the textarea has cols="50" and rows="10"

<textarea class="form-control" name="placeOfDeath" cols="50" rows="10" id="placeOfDeath"></textarea>

I want a way to control these numbers, I have checked the documentation but couldnt spot anything?

like image 867
Jonny C Avatar asked May 07 '15 17:05

Jonny C


2 Answers

The options (third parameter) array is actually the attributes array of that element, you so can just pass any 'key' => 'value' and the element will have it as attributes, for example:

{!! Form::textarea('placeOfDeath',null,['class'=>'form-control', 'rows' => 2, 'cols' => 40]) !!}
like image 88
Pawel Bieszczad Avatar answered Sep 28 '22 04:09

Pawel Bieszczad


I have accepted the other answer as it works perfectly.

I have also found that the class actually checks for an attribute size

protected function setQuickTextAreaSize($options)
{
    $segments = explode('x', $options['size']);

    return array_merge($options, array('cols' => $segments[0], 'rows' => $segments[1]));
}

Its a minor space saving, Im not sure it makes the code anymore readable, but it is an alternative to cut off a few characters

['size' => '30x5']
like image 36
Jonny C Avatar answered Sep 28 '22 04:09

Jonny C