php 将行数调整为 Form::Textarea Laravel 5

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30107501/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:32:42  来源:igfitidea点击:

Adjust number of Rows to Form:: Textarea Laravel 5

phphtmllaravellaravel-5

提问by Jonny C

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

如何使用Illuminate\Html\FormFacade该类控制添加到 textarea 的行数?

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 有cols="50"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?

我想要一种控制这些数字的方法,我已经检查了文档但找不到任何东西?

回答by Pawel Bieszczad

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:

选项(第三个参数)数组实际上是该元素的属性数组,因此您可以只传递 any'key' => 'value'元素并将其作为属性,例如:

{!! Form::textarea('placeOfDeath',null,['class'=>'form-control', 'rows' => 2, 'cols' => 40]) !!}

回答by Jonny C

I have accepted the other answer as it works perfectly.

我已经接受了另一个答案,因为它完美无缺。

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

我还发现该类实际上检查了一个属性 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']

回答by Rajan Gupta

Also try this:

也试试这个:

{!! Form::textarea('placeOfDeath',null, array('class'=>'form-control', 
                    'rows' => 10, 'cols' => 50)) !!}