1

I'm looking to add a blank titled label field to a laravel form. However when I leave the "title" field blank and chose a "for" input it automatically assigns this to the label title.

{{ Form::label('name', '', array('class' => 'label-input', 'id' => 'name'))  }}

I've tried leaving the field blank and null, but it automatically fetches the "for" label. This is the output:

<label for="Name" class="label-input" id="name">Name</label>

Thank you in advance,

Dan

jsldnppl
  • 915
  • 1
  • 9
  • 28

3 Answers3

1

You may use a custom macro, like

Form::macro('emptyLabel', function($name, $options = array())
{
    $options = Html::attributes($options);
    return '<label for="'.$name.'"'.$options.'></label>';
});

Use it as

{{ Form::emptyLabel('name', array('class' => 'label-input', 'id' => 'name')) }}

Output will be

<label for="name" class="label-input" id="name"></label>

You may add the macro in your app/start/global or filtes, even in routes.

The Alpha
  • 143,660
  • 29
  • 287
  • 307
0

The simplest possible solution

{{ Form::open() }}
    {{ Form::label('name', '&nbsp;') }}
    {{ Form::text('name') }
{{ Form::close() }}
Andreyco
  • 22,476
  • 5
  • 61
  • 65
  • This will keep the element block and disrupt flow of the page. It also doesn't have text for screen readers which is part of what labels are good for. – Dustin Fraker Dec 04 '14 at 05:25
0

Take a look at how twitter bootstrap does this. I think it is a nice solution. If you are using bootstrap in your project just ad the .sr-only class to the label. Otherwise add the css to your own file and it should work. It is a good practice to include the label text for screen readers anyway. sr-only stands for screen reader only!

Here is the code that they are using for this class:

.sr-only {
   position: absolute;
   width: 1px;
   height: 1px;
   padding: 0;
   margin: -1px;
   overflow: hidden;
   clip: rect(0,0,0,0);
   border: 0
 }
Dustin Fraker
  • 524
  • 1
  • 5
  • 9