# Aurelia-validation issue

**URL:** <https://discourse.aurelia.io/t/aurelia-validation-issue/1029>\
**Category:** Help Requests\
**Created:** [April 3, 2018, 8:56pm UTC](https://discourse.aurelia.io/t/aurelia-validation-issue/1029 "2018-04-03T20:56:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmdavid](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/jmdavid/32/779_2.png) [@jmdavid](https://discourse.aurelia.io/u/jmdavid)\
**Post date:** [April 3, 2018, 8:56pm UTC](https://discourse.aurelia.io/t/aurelia-validation-issue/1029/1 "2018-04-03T20:56:51Z")

</div>

I try to add validation dynamically but validate method returns only the first error.  
My goal is to parse a json with all validation rules from the server and add validation dynamically.

my html:

```
<input id="myInput1" value.bind="myInput1 & validateOnChangeOrBlur" errors.bind="myInput1Errors"/>
<input id="myInput2" value.bind="myInput2 & validateOnChangeOrBlur" errors.bind="myInput2Errors"/>
<button click.delegate='validate()'>validate</button>

    <ul if.bind="controller.errors">
      <li repeat.for="error of controller.errors">
        ${error.message}
      </li>
    </ul>

```

My .ts:

```
attached() {
      let rules = [];
      //my real code is a for loop for adding dynamically
      rules.push(ValidationRules
                        .ensure('myInput1')
                        .required()
                        .rules[0]);
      rules.push(ValidationRules
                        .ensure('myInput2')
                        .required()
                        .rules[0]);
     this.controller.addObject(this, rules);
    }

 validate() {
          this.controller.validate()
                .then(result => {
                    if (result.valid) {
                        //
                    } else {
                       //
                    }
                });
        }

```

When I blur (tab navigation), validate method shows errors correctly, stacking them one after another.  
When I call validate, it shows only the first one.

However, if I do this statically, it works (both blur and validate):

```
ValidationRules
            .ensure('myInput1')
            .required()
            .ensure('myInput2')
            .required()
            .on(this);

```

So what’s wrong with adding it dynamically?

Thanks.

---

<div class="post-metadata">

**Author:** ![jmdavid](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/jmdavid/32/779_2.png) [@jmdavid](https://discourse.aurelia.io/u/jmdavid)\
**Post date:** [April 3, 2018, 10:51pm UTC](https://discourse.aurelia.io/t/aurelia-validation-issue/1029/2 "2018-04-03T22:51:41Z")

</div>

I created a gistrun for that: [https://gist.run/?id=c60ee8a86c9c473b97e930e117fd68df](https://gist.run/?id=c60ee8a86c9c473b97e930e117fd68df)
