3

I have

a text area. I load a default value from a file into it (d5), but for some reasons, it give me so many space in front of that value.

enter image description here

I tried

PHP

    $filename = public_path().'/file/external/header.txt';
    $handle = fopen($filename, "r");
    $header = fread($handle, filesize($filename));
    fclose($handle);

Blade

<div class="form-group">
    <label class="col-sm-12 control-label">Description</label>
    <div class="col-sm-12">
        <textarea name="description" class="form-control" rows="5" placeholder="Desciption">
            {{$description}}
        </textarea>
    </div>
</div>

Try#2

Take off class form-group from my parent div.

<div class="form-group">
  <label class="col-sm-12 control-label">Description</label>
  <div class="col-sm-12">
    <textarea name="description" class="form-control" rows="5" placeholder="Desciption">
      {{$description}}
    </textarea>
  </div>
</div>

I got

enter image description here


Try#3

Take off class form-control from my text-area element.

<div class="">
  <label class="col-sm-12 control-label">Description</label>
  <div class="col-sm-12">
    <textarea name="description" class="" rows="5" placeholder="Desciption">
      {{$description}}
    </textarea>
  </div>
</div>

I got

enter image description here


  • Why does it do that ?
  • Did I do anything wrong here ?
  • How do I stop that ?
Community
  • 1
  • 1
code-8
  • 54,650
  • 106
  • 352
  • 604

1 Answers1

11

You have indentations in the html. ANYTHING that appears between the opening/closing <textarea> tags becomes PART of the text area:

<div class="col-sm-12">
    <textarea name="description" class="form-control" rows="5" placeholder="Desciption">
                                                                                        ^
        {{$description}}
^^^^^^^^                ^
    </textarea>
^^^^
</div>

The ^ mark the spaces you're getting. If you don't want those spaces, then don't have them:

<textarea>foo</textarea>

v.s.

<textarea>
          ^--line break at start of textarea content
    foo
^^^^----spaces
       ^--another line break
</textarea>
Marc B
  • 356,200
  • 43
  • 426
  • 500