Laravel:当存在/isn';var$error中没有错误吗?
如果在一个特定的输入中有一个错误,我想突出显示它并对其进行聚焦,它就会按预期工作 但是,如果没有错误(默认情况),则第一个输入应该聚焦,而不是聚焦。如何将这两个选项添加到阵列中?请看第一组表格Laravel:当存在/isn';var$error中没有错误吗?,laravel,laravel-5,laravel-form,Laravel,Laravel 5,Laravel Form,如果在一个特定的输入中有一个错误,我想突出显示它并对其进行聚焦,它就会按预期工作 但是,如果没有错误(默认情况),则第一个输入应该聚焦,而不是聚焦。如何将这两个选项添加到阵列中?请看第一组表格 <div class="form-group {{ $errors->has('name') ? ' has-error' : '' }}"> {{ Form::text('name', null, [ (!$errors) ? 'autofocus' : '',
<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>
{{Form::text('name',null[
(!$errors)?“自动对焦”:“”,//如果没有错误,则自动对焦,因为默认
($errors->has('name'))?“自动对焦”:“”//如果名称中有错误,则自动对焦
]) }}
{{Form::email('email',null[
($errors->has('email'))?'autofocus':''//如果电子邮件中有错误,则自动对焦
]) }}
{{Form::password('password'[
($errors->has('password'))?“自动对焦”:“”//
]) }}
这应该可以:
....
'autofocus' => $errors->has('password') ? 'autofocus' : null,
....
我这样做是为了所有人:“自动对焦”=>(!$errors)?”自动对焦':''自动对焦'=>($errors->has('name'))?'自动对焦':''自动对焦“=>($errors->has('email'))?”自动对焦':''自动对焦'=>($errors->has('password'))?'自动对焦':'';现在,无论是否有错误,只有名称字段是自动聚焦的。请尝试$errors->first('email')这样的方法