在Laravel中显示文本区域的数值。

huangapple go评论70阅读模式
英文:

Display textarea value in Laravel

问题

I have posts. When I click edit it takes me to the edit screen and display current post values. However for some reason the input is displayed while textarea is not. I can't understand why.

Works perfectly, displays value.

It doesn't display value for body.

英文:

I have posts. When I click edit it takes me to the edit screen and display current post values. However for some reason the input is displayed while textarea is not. I can't understand why.

Works perfectly, displays value.

<input class = "form-control" type="text" name = 'body' value = "{{ old('body', $post->body ?? null) }}" />

It doesn't display value for body.

<textarea class="form-control" type="text" name = 'body'  rows="3" value = "{{ old('body', $post->body ?? null) }}" ></textarea>

在Laravel中显示文本区域的数值。

答案1

得分: 4

输入是自闭合标签,这就是为什么在输入中你可以通过 value= 来设置值,而在文本区域中有闭合标签,这就是为什么在文本区域中你不能通过 value 属性来设置值。

<textarea class="form-control" type="text" name = 'body'  rows="3"> {{ old('body', $post->body) }}</textarea>
英文:

input is self closing tag that's why in input you can set value via value=
and in textarea there is closing tag that's why in textarea you can't set value via value attribute

<textarea class="form-control" type="text" name = 'body'  rows="3"> {{ old('body', $post->body) }}</textarea>

答案2

得分: 1

textarea标签没有值,但在handlebars中可以正常工作。它具有占位符属性,但在这里不像这样工作:https://html.spec.whatwg.org/multipage/forms.html#attr-textarea-placeholder
因此,只需在闭合标签之前提供值

<textarea class="form-control" type="text" name='body' rows="3">{{ old('body', $post->body ?? null) }}</textarea>
英文:

The textarea tag has no value, but work fine with handlebars.it has placeholder attribute but here it not work like this https://html.spec.whatwg.org/multipage/forms.html#attr-textarea-placeholder
So just give the value before close tag

&lt;textarea class=&quot;form-control&quot; type=&quot;text&quot; name = &#39;body&#39;  rows=&quot;3&quot; &gt;{{ old(&#39;body&#39;, $post-&gt;body ?? null) }}&lt;/textarea&gt;

答案3

得分: 0

<div class="form-group col-md-6">
    <label class="control-label">Vendor Description</label>
    <textarea name="dec" class="form-control" rows="3" value="{{ old('dec') }}"></textarea> {!! $errors->first('dec', '<p class="text-danger errorBag">:message</p>') !!}

    <label class="control-label">Last Name</label>
    <input type="text" name="l_name" class="form-control" value="{{ old('l_name') }}"> {!! $errors->first('l_name', '<p class="text-danger errorBag">:message</p>') !!}
</div>
英文:

**Display textarea value in Laravel

&lt;div class=&quot;form-group col-md-6&quot;&gt;
            &lt;label class=&quot;control-label&quot;&gt;Vendor Description&lt;/label&gt;
            &lt;textarea name=&quot;dec&quot; class=&quot;form-control&quot; rows=&quot;3&quot; value=&quot;{{old(&#39;dec&#39;)}}&quot;&gt;&lt;/textarea&gt; {!! $errors-&gt;first(&#39;dec&#39;, &#39;
            &lt;p class=&quot;text-danger errorBag&quot;&gt;:message&lt;/p&gt;&#39;) !!}
        
              
            &lt;label class=&quot;control-label&quot;&gt;Last Name&lt;/label&gt;
            &lt;input type=&quot;text&quot; name=&quot;l_name&quot; class=&quot;form-control 
                            &quot; value=&quot;{{old(&#39;l_name&#39;)}}&quot;&gt; {!! $errors-&gt;first(&#39;l_name&#39;, &#39;
            &lt;p class=&quot;text-danger errorBag&quot;&gt;:message&lt;/p&gt;&#39;) !!}
        &lt;/div&gt;

huangapple
  • 本文由 发表于 2020年1月3日 17:18:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/59575875.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定