当前位置: 动力学知识库 > 问答 > 编程问答 >

laravel - Disable drop down?

问题描述:

I've checked this answer:

SO

But with no luck.

I need the first item in my dropdown to be disabled. How can I do this using the form builder?

Form::select('my-select', array('please-select' => 'please select', 'a' => 'apple'))

网友答案:

I wrote my own macro for that. I don't think laravel has any default way of doing it.

HTML::macro('mySelect', function($value, $extras)
{
    $build = array();
    foreach ($value as $key => $val) {
        $build[] = sprintf('<option>%s</option>', $val);
    }
    $build[0] = sprintf('<option disabled>%s</option>', $value[1]);
    return sprintf('<select>%s</select>', implode("", $build));
});

This macro can go to app > start > global.php of the laravel project.

Hope this helps

分享给朋友:
您可能感兴趣的文章:
随机阅读: