TextArea 中的 Laravel 值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40340892/
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
Laravel value in TextArea
提问by MaximeBTD
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 :
我在 Laravel 和 HTML 的文本区域遇到一个奇怪的问题,我不知道如何绕过它。这是我的 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 ?
表格写在 textarea 中。所以如果我删除所有缩进,结果是正确的,但我的代码不是(我不能留下这样的一部分代码)。有什么解决方案可以避免文本区域中的选项卡?
回答by user2879055
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 的问题,因为您的代码中有选项卡,它还会将这些选项卡/空格添加到 HTML 中。所以你需要做的是把整个 foreach 变成这样的一行:
<textarea class="form-control" id="comment">@foreach ($comments as $com){{$com->comment}}@endforeach</textarea>
use HTML or CSS to style it correctly
使用 HTML 或 CSS 正确设置样式
回答by Ghost Worker
change {{$com->comment}}
to {{trim($com->comment)}}
that should solve your problem
更改{{$com->comment}}
为{{trim($com->comment)}}
应该可以解决您的问题
回答by Plycoder
Use following regular expression to replace tabs from your string then it assign on textarea:
使用以下正则表达式替换字符串中的制表符,然后在 textarea 上分配:
preg_replace('/\t/g', '',"your string")
Or update your scripts as followings:
或按以下方式更新您的脚本:
@foreach ($comments as $com)
{{preg_replace('/\t/g', '', $com->comment)}}
@endforeach
回答by javielrezende
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
问题在于@else 和@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