有没有办法Form::label
与复选框和单选输入一起使用来生成引导建议的标记?目的是使输入字段位于标签内,而不是将其附加到id
s。我想避免对标记进行硬编码Form::radio
<div class="checkbox">
<label>
<input type="checkbox" value="">
Option one is this and that—be sure to include why it's great
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
Option one is this and that—be sure to include why it's great
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">
Option two can be something else and selecting it will deselect option one
</label>
</div>
您可以只编写自己的表单宏,然后使用它来构建html(随您喜欢)。
http://laravel.com/docs/4.2/html#custom-macros
就像是:
Form::macro('bootCheckbox', function($value, $label)
{
$html = '<div class="checkbox"><label><input type="checkbox" value="';
$html .= $value;
$html .= '">';
$html .= $label;
$html .= '</label></div>'
return $html
}
然后,您可以在视图中这样称呼它:
{{ Form::bootCheck('i_dont_know_what_value_youd_like', 'Option one is this and that—be sure to include why it's great') }}
当然,您可以将所需的任何值传递给宏并构建所需的任何对象(假设宏端的代码是正确的)。上面的示例应显示您所显示的复选框,但是它不太干净,我还没有对其进行测试。
至于将代码放置在哪里,只要链接它就可以将其放置在任何地方。我的表单宏(范围更广)位于/app/start/form_macros.php中,并且只需添加require dirname(__FILE__) . '/form_macros.php';
到/app/start/global.php中就可以了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句