我的表单采用bootstrap4
设置,并使用ember-cp-validations
进行验证。
<div class="form-group {{if showNameError 'has-danger' ''}}">
<label for="name" class="cols-sm-2 control-label">Full Name</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon">{{fa-icon "user"}}</span>
{{input id="name" class="form-control" value=user.firstname placeholder="Enter your Name" focus-out=(action (mut showNameError) true)}}
</div>
</div>
{{#if showNameError}}
{{#if (v-get user "firstname" "isInvalid")}}
<div class="form-control-feedback container">
<span>{{v-get user 'firstname' 'message'}}</span>
</div>
{{/if}}
{{/if}}
</div>
使用{{if showNameError 'has-danger' ''}}
,我可以在has-danger
为真时将类设置为showNameError
,但是当它为false时,类仍保留在那里且has-danger
仍然存在。
答案 0 :(得分:0)
已更改为并且正在按预期执行。
<div class="form-group {{if showNameError (if (v-get user 'firstname' 'isInvalid') 'has-danger' 'has-success')}}">
<label for="name" class="cols-sm-2 control-label">Full Name</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon">{{fa-icon "user"}}</span>
{{input id="name" class="form-control" value=user.firstname placeholder="Enter your Name" focus-out=(action (mut showNameError) true)}}
</div>
</div>
{{#if showNameError}}
<div class="form-control-feedback container">
<span>{{v-get user 'firstname' 'message'}}</span>
</div>
{{/if}}