# Aurelia validation error "Error: Unable to parse accessor function: function (c) { return c.client.clientLastName; }"

**URL:** <https://discourse.aurelia.io/t/aurelia-validation-error-error-unable-to-parse-accessor-function-function-c-return-c-client-clientlastname/603>\
**Category:** Help Requests\
**Created:** [January 7, 2018, 5:03am UTC](https://discourse.aurelia.io/t/aurelia-validation-error-error-unable-to-parse-accessor-function-function-c-return-c-client-clientlastname/603 "2018-01-07T05:03:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![si2030](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/si2030/32/275_2.png) [@si2030](https://discourse.aurelia.io/u/si2030)\
**Post date:** [January 7, 2018, 5:03am UTC](https://discourse.aurelia.io/t/aurelia-validation-error-error-unable-to-parse-accessor-function-function-c-return-c-client-clientlastname/603/1 "2018-01-07T05:03:44Z")

</div>

I have asked a very similar question about this on SO [here.](https://stackoverflow.com/questions/48134052/aurelia-validation-rules-getting-error-unable-to-parse-accessor-function)

Aurelia validation works for a simple bind where I might have a single variable in the view model and then access that in the view like so:

```
<input type="password" value.bind="password & validate" class="form-control" id="password" placeholder="Password">

```

and in the view model:

```
ValidationRules.ensure((v: Login) => v.username)
.displayName("User Name")
.required()
.on(Login);

```

This works at the moment and I get an error if I fail to enter anything and tab out. Great…

If on the other hand I am instead using an object variable set to an interface eg: `client: ClientDetails;` in my view-model.

```
export class Client {
controller: ValidationController;
client: ClientDetails;
 ...

```

where the view has it showing:

```
<input type="text" value.bind="client.clientLastName & validate" class="form-control" id="lastname" placeholder="Last Name...">

```

and I set the validation rules like so:

```
ValidationRules.ensure((c:Client) => c.client.clientLastName)
.displayName("Last name")
.required()
.on(Client);

```

I get the following error:

`Error: Unable to parse accessor function: function (c) { return c.client.clientLastName; }`

“client” here is set to an interface type… clientLastName is one of a number of members of this object variable.

How do I handle the syntax when all the inputs are bound to variables that are part of a larger object?

---

<div class="post-metadata">

**Author:** ![si2030](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/si2030/32/275_2.png) [@si2030](https://discourse.aurelia.io/u/si2030)\
**Post date:** [January 8, 2018, 9:09am UTC](https://discourse.aurelia.io/t/aurelia-validation-error-error-unable-to-parse-accessor-function-function-c-return-c-client-clientlastname/603/2 "2018-01-08T09:09:23Z")

</div>

So is this a limitation of Aurelia validation? It only works on basic variables and not on elements of an object…

It works on a simple variable on the same page but not on a variable that is part of a larger object set to an interface…

---

<div class="post-metadata">

**Author:** ![ormasoftchile](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ormasoftchile/32/340_2.png) [@ormasoftchile](https://discourse.aurelia.io/u/ormasoftchile)\
**Post date:** [January 8, 2018, 2:14pm UTC](https://discourse.aurelia.io/t/aurelia-validation-error-error-unable-to-parse-accessor-function-function-c-return-c-client-clientlastname/603/3 "2018-01-08T14:14:10Z")

</div>

Not 100% sure, but the expression (c:Client) =\> c.client.clientLastName) may be wrong.  
c is already a Client instance, so I guess it should be: (c:Client) =\> c.clientLastName)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![si2030](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/si2030/32/275_2.png) [@si2030](https://discourse.aurelia.io/u/si2030)\
**Post date:** [January 8, 2018, 7:59pm UTC](https://discourse.aurelia.io/t/aurelia-validation-error-error-unable-to-parse-accessor-function-function-c-return-c-client-clientlastname/603/4 "2018-01-08T19:59:40Z")

</div>

Thanks for replying. I tried that and its underlining "clientLastName in red unfortunately.

 ![validation](https://canada1.discourse-cdn.com/flex027/uploads/aurelia/original/1X/17032f3662cc5ac364c8f1079c04b7af055f59d9.png)

---

<div class="post-metadata">

**Author:** ![justcoding](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@justcoding](https://discourse.aurelia.io/u/justcoding)\
**Post date:** [January 9, 2018, 11:38pm UTC](https://discourse.aurelia.io/t/aurelia-validation-error-error-unable-to-parse-accessor-function-function-c-return-c-client-clientlastname/603/5 "2018-01-09T23:38:02Z")

</div>

If I understand your problem and the documentation correctly (haven’t done much with the validation before):  
You can assign rules to classes and instances via `.on(...)` Because interfaces only are used in TypeScript and don’t exist in plain JS Aurelia can’t find the proper ValidationRules for your object. Therefore you have to pass the exact instance or use a class as these stay in JS after transpilation.

---

<div class="post-metadata">

**Author:** ![huochunpeng](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@huochunpeng](https://discourse.aurelia.io/u/huochunpeng)\
**Post date:** [January 10, 2018, 4:45am UTC](https://discourse.aurelia.io/t/aurelia-validation-error-error-unable-to-parse-accessor-function-function-c-return-c-client-clientlastname/603/6 "2018-01-10T04:45:55Z")

</div>

The subproperties feature is not implemented yet.

> <https://github.com/aurelia/validation/issues/283>

---

<div class="post-metadata">

**Author:** ![huochunpeng](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@huochunpeng](https://discourse.aurelia.io/u/huochunpeng)\
**Post date:** [January 10, 2018, 5:03am UTC](https://discourse.aurelia.io/t/aurelia-validation-error-error-unable-to-parse-accessor-function-function-c-return-c-client-clientlastname/603/7 "2018-01-10T05:03:13Z")

</div>

The project I am working on requires complex validation on complex model. I have built a custom validation tool for it. It should cover your use case, if you are willing to have a look.

Beware it is a generic tool, doesn’t provide glue code to Aurelia component. In Aurelia app, you need to at least do (1) when model changes, run validation again to produce an error object, (2) bind the error object to your view, I mean using `"error.sub.prop"`.

> **[buttonwoodcx/bcx-validation](https://github.com/buttonwoodcx/bcx-validation)**
>
> Yet another validation tool to validate complex model, but simple and flexible to use. - buttonwoodcx/bcx-validation
