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?
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]) !!}
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With