1

如果特定输入中有错误,我想突出显示它并聚焦它,它会按预期工作。

但是,如果没有错误(默认情况),第一个输入应该聚焦,但它没有。如何将这两个选项添加到数组中?看一下第一个表单组。

<div class="form-group {{ $errors->has('name') ? ' has-error' : '' }}">
    {{ Form::text('name', null, [
        (!$errors) ? 'autofocus' : '',        // if no errors, autofocus because default
        ($errors->has('name')) ? 'autofocus' : ''   // if error in name, autofocus
    ]) }}
</div>

<div class="form-group {{ $errors->has('email') ? ' has-error' : '' }}">
    {{ Form::email('email', null, [
        ($errors->has('email')) ? 'autofocus' : ''   // if error in email, autofocus
    ]) }}
</div>

<div class="form-group {{ $errors->has('password') ? ' has-error' : '' }}">
    {{ Form::password('password', [
        ($errors->has('password')) ? 'autofocus' : ''   // if error in password, autofocus
    ]) }}
    </div>
</div>
4

1 回答 1

1

这应该有效:

....
'autofocus' => $errors->has('password') ? 'autofocus' : null,
....
于 2016-09-01T04:21:19.667 回答