Reputation: 49
I'm getting a strange issue with Laravel and HTML's Text Areas and I can't figure out how to bypass it. Here is the code of my textarea :
<div class="col-md-3">
<label for="comment">Commentaire:</label>
<textarea class="form-control" id="comment">
@foreach ($comments as $com)
{{$com->comment}}
@endforeach
</textarea>
</div>
So I'm getting multiples results from my controller, and I would like to add all of them to the text box. The problem I have is indentation.
The tabulations are written in the textarea. So if i delete all indentation, result is correct, but my code isn't (I can't leave a part of code like that). Any solution to avoid the tabs in the text area ?
Upvotes: 3
Views: 27246
Reputation: 21
In my code there was only a blank space. I resolved it as follows:
Problem:
<textarea id="inputDescriptionEs" class="form-control" name="description_es" rows="4" required>@isset($data){{$data->description_es}}@else @endIf</textarea>
The problem was with the space between @else and @endIF
Solution:
@isset($data)
<textarea id="inputDescriptionEs" class="form-control" name="description_es"
rows="4" required>{{$data->description_es}}</textarea>
@else
<textarea id="inputDescriptionEs" class="form-control" name="description_es" rows="4" required></textarea>
@endIf
Upvotes: 1
Reputation: 726
Use following regular expression to replace tabs from your string then it assign on textarea:
preg_replace('/\t/g', '',"your string")
Or update your scripts as followings:
@foreach ($comments as $com)
{{preg_replace('/\t/g', '', $com->comment)}}
@endforeach
Upvotes: 0
Reputation: 690
change {{$com->comment}}
to {{trim($com->comment)}}
that should solve your problem
Upvotes: 0
Reputation: 176
I think that's a problem with textarea's because you have tabs in your code it will also add those tabs/spaces into the HTML. So what you need to do is make the entire foreach into one line like this:
<textarea class="form-control" id="comment">@foreach ($comments as $com){{$com->comment}}@endforeach</textarea>
use HTML or CSS to style it correctly
Upvotes: 3