Adjust number of Rows to Form:: Textarea Laravel 5

31,632

Solution 1

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]) !!}

Solution 2

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']

Solution 3

Also try this:

{!! Form::textarea('placeOfDeath',null, array('class'=>'form-control', 
                    'rows' => 10, 'cols' => 50)) !!}
Share:
31,632
Jonny C
Author by

Jonny C

Long time observer

Updated on July 05, 2022

Comments

  • Jonny C
    Jonny C almost 2 years

    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?

  • Azeame
    Azeame about 9 years
    I never thought of, extracting this to its own helper, interesting.