Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aurelia Validation Rules: Unable to parse accessor function

Tags:

aurelia

It seems there have been various problems elsewhere in regards to the aurelia-validation module, but I haven't seen anything that has addressed the specific problem I've been running into.

I have a model class with the definition and validation rules as below:

my-model.js

my-model = {
    "name":
        {
        "full": "",
        "short": "",
        }
    };

...

ValidationRules
    .ensure(model => model.name.full).required().minLength(5).maxLength(50)
    .on(this.my-model);

When I try it in the browser, however, I get the error:

...
Inner Error:
Message: Unable to parse accessor function:
function (model) {
                        return model.name.full;
                    }
...

This question was the closest I was able to see to my problem, and another here seems to be having the same issue.

I am running aurelia-framework@^1.0.2 and aurelia-validation@^1.0.0-beta.1.0.1 which I believe are just the defaults from regular updates (but also the reason for it suddenly not working). Is it possible I'm still running incompatible versions of some modules? Or is there somewhere elsewhere in my code that I need to fix?

like image 742
cchapman Avatar asked Jan 11 '17 19:01

cchapman


1 Answers

What if you target the property instead of the object? Does that work?

myModel = {
  "name": {
    "full": "",
    "short": "",
  }
};

ValidationRules
  .ensure(model => model.full)
    .required()
    .minLength(5)
    .maxLength(50)
  .on(this.myModel.name); //<--- see
like image 112
Fabio Luz Avatar answered Oct 13 '22 22:10

Fabio Luz