Aurelia 验证器不更新 UI

Aurelia validator doesn't update UI

使用 aurelia-validator 插件,即使表单提交和验证代码正常工作,所有属性都正确更新,UI 没有改变,就像我没有得到红色 window 围绕不正确的属性,也不是给定形式的错误陈述 属性。 它没有连接到我的 CSS,我尝试删除整个 css 但它仍然不起作用。知道这里出了什么问题吗?遗漏了什么?

contact.js

import {inject} from 'aurelia-framework';
import {Validation} from 'aurelia-validation';


@inject(Validation)
export class Contact{

  firstName = 'John';
  lastName = '';
  company = '';
  subject = 'product question';
  email = '';
  messageText = 'test';

  constructor(validation){
    this.validation = validation.on(this)
      .ensure("firstName")
        .isNotEmpty()
      .ensure("lastName")
        .isNotEmpty()
      .ensure("email")
        .isNotEmpty()
        .isEmail();

  }

  contact(){
    this.validation.validate()
      .then(() => {
          console.log("works");
        })
      .catch(() => {
          console.log("error");
        });
  }

}

contact.html

<template>
<div class="row contact-container">
    <div class="col-md-4 col-md-offset-3">
        <form role="form" validate.bind="validation" submit.delegate="contact()">
                <label>First Name</label>
                <input type="text" value.bind="firstName" class="form-control" >

                <label>Last name</label>
                <input type="text" value.bind="lastName" class="form-control">

                <label>Company</label>
                <input type="text" value.bind="company" class="form-control">

                <label>Email</label>
                <input type="text" value.bind="email" class="form-control">

                <label >Subject</label>
                <select  value.bind="subject" class="form-control">
                    <option value="product question">Product Question</option>
                    <option value="cooperation">Cooperation</option>
                    <option value="Other">Other</option>

                </select>

                <label for="message">Message</label>
                <textarea rows="5" id="message" value.bind="messageText" class="form-control"></textarea>
                <br></br>

                <input type="submit"  class="form-control">


        </form>
    </div>
</div>
</template>

使用 form-group class,不要在 input 上忘记 validate 试试

<div class="form-group">
 <label class="col-sm-3">Land</label>              
 <div class="col-sm-6">
   <input class="input-small col-sm-12" type="text" 
          placeholder="Land"
          value.bind="model.item.country" validate="country">
 </div>
</div>

我想这个问题与您的标记与您使用的 ViewStrategy 不匹配有关。

我怀疑您可能正在使用 Aurelia 提供的一些 ViewStragegy,例如 https://github.com/aurelia/validation/blob/master/doc/Intro.md#configuseviewstrategyviewstrategyinstance that expects Twitter Bootstrap markup. If that is the case, You should group Your form intputs to form-groups - see the demo (http://aurelia.io/validation/#/) and source of the TWBootstrapViewStrategyBase class: https://github.com/aurelia/templating-validation/blob/master/src/strategies/twbootstrap-view-strategy.js#L11