Adjust number of Rows to Form:: Textarea Laravel 5 - php

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

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

Related

Laravel - Select input not keeping old value

I have a piece of code:
{!! Form::select('option_employee_review', old('option_employee_review', $employeeReviews), $employeeReviews, ['id' => 'option_employee_review', 'class' => 'form-control ']); !!}
It saves the value to the database correct. When i go to edit the item again the select input does not keep the old value that's in the database. How do i make it so that the select input does keep its old value.
$employeeReviews:
[
2843 => "Medewerker review 1"
2849 => "Medewerker review 2"
]
I am not using your syntax, but something like this will do I think.
<option value="{{$channel->id}}" {{ (old("channel_id") == $channel->id ? "selected" : "" ) }}>{{$channel->title}}</option>
Second parameter to select function must be array of options.
Try changing it like this
{!! Form::select('option_employee_review', $employeeReviews, old('option_employee_review', $employeeReviews), ['id' => 'option_employee_review', 'class' => 'form-control ']); !!}
Or based on your parent object let's say employee you can try
{!! Form::select('option_employee_review', $employeeReviews, $employee->option_employee_review, ['id' => 'option_employee_review', 'class' => 'form-control ']); !!}

Why do I have such field names in my laravel project, despite all others are OK?

I'm trying to configure simple laravel booking form for my project, but the names of fields are like this "quickadmin.bookings.fields.first_name*" but not like I want them to be, like this "first name".
I've tried to look through all files of project, where those forms could be configured, but due to lack of experience I can't find anything.
Here's some code from create.blade.php file
<div class="row">
<div class="col-xs-12 form-group">
{!! Form::label('first_name', trans('quickadmin.bookings.fields.first_name').'*', ['class' => 'control-label']) !!}
{!! Form::text('first_name', old('first_name'), ['class' => 'form-control', 'placeholder' => '', 'required' => '']) !!}
<p class="help-block"></p>
#if($errors->has('first_name'))
<p class="help-block">
{{ $errors->first('first_name') }}
</p>
#endif
</div>
</div>
I want the field to be named more common, like "First name".
That's not a field name but an item from the translation files. So you should have in the resources/lang/en (en, or whatever language you use) a quickadmin.php file that contains an array like this:
return [
'bookings' => [
'fields' => [
'first_name' => 'First name'
]
]
];
If you want to simplify this, then remove some of the arrays.
And you get this "quickadmin.bookings.fields.first_name*" on the screen because the file and the array that I mentioned above are probably missing. So you can avoid that by creating what I just said, or create your own, just remember the first part is the filename, then it follows the items from the array.

Laravel Form::select shows nothing

Hi I'm using Laravel version 5.6 and got a problem in view with Form::select.
I already made some Form::open with 'text' and 'textarea' they all worked fine, but the Form::select do not generate the select fild on my view.
I used this code:
{!! Form::label('isPropaganda', 'Propaganda:') !!}
{!! Form::select('isPropaganda', ['Não' => '0', 'Sim' => '1'], null, ['class'=>'form-control','multiple']) !!}
I found the example here http://laravel-recipes.com/recipes/163/creating-a-select-box-field but didn't workout. How can I fix it?
Try flipping the keys and values. Keys cannot have special characters in them. Also, I'm not sure what that 'multiple' attribute is doing there. If it's meant to be a css class, place it inside the 'class' array key, otherwise add it to a new attributes array.
{!! Form::select('isPropaganda', ['0' => 'Não', '1' => 'Sim'], null, ['class'=>'form-control multiple']) !!}

Laravel - htmlentities() expects parameter 1 to be string, array given

My blade.php code is:
{!! Form::input('text', 'tactic[]', null, array('id' => 'tactic', 'class' => ' form-control TabOnEnter', 'placeholder' => 'Tactics_1')) !!}
HtmlBuilder.php code is
public function escapeAll($value)
{
return htmlentities($value, ENT_QUOTES, 'UTF-8');
}
The error message is:
ErrorException in HtmlBuilder.php line 65:
htmlentities() expects parameter 1 to be string, array given (View: /home/seyali-02/dev/htdocs/scam/resources/views/dashboard/Scam/edit.blade.php)
And i have changed the blade.php as like
{!! Form::input('text','', 'tactic[]', null, array('id' => 'tactic', 'class' => ' form-control TabOnEnter', 'placeholder' => 'Tactics_1')) !!}
and
{!! Form::text('name', 'tactic[]', null, array('id' => 'tactic', 'class' => ' form-control TabOnEnter', 'placeholder' => 'Tactics_1')) !!}
and also text('text', .. But nothing works for me and throwing me the same error as i mentioned above.. I have gone through all the similar questions related to this but none of those answers solved my problem . So please avoid doing duplication of this question and give me clear and correct solution..
You are adding tactic[] to the name which is an array and hence when you post the data it is going as an array. Either remove it or at php end use implode.
If you want to take the input as an array then you can use this code
{!! Form::text('tactic[]',null,['id' => 'tactic', 'class' => ' form-control TabOnEnter', 'placeholder' => 'Tactics_1']) !!}

Adding classes/ids to forms in Laravel 4

I am trying to add classes and ids to specific elements of a form in Laravel 4. For example, I would like this:
<textarea type="text" id="description" onfocus="this.value=''; setbg('#f0f7f8');" onblur="setbg('white')" name="description" value="" rows="10"></textarea>
to be applied to:
{{ Form::label('description', 'Description:') }}
{{ Form::textarea('description')}}
I didn't see this in the documentation. Thank you!
Use the third parameter for the Form::textarea method, passing a key-value array. Ex:
Form::textarea('description', null, [
'id' => 'description',
'rows' => 10,
]);
Although its an old question, I just wanted to say that you can escape the javascript like this:
Form::textarea('description', null, array(
'id' => 'description',
'rows' => 10,
'onFocus' => 'this.value=\'\'; setbg(\'#f0f7f8\');'
));
Thats it :)

Categories