Configuration of aurelia-validation
Asked Answered
P

3

6

I'm trying to configure Aurelia Validation (release 0.2.6) to get all of the validation messages appended to <input> element instead of label.

My main.js looks like this:

export function configure(aurelia) {
aurelia.use
  .standardConfiguration()
  .developmentLogging()
  .plugin('aurelia-validation', (config) => { config.useLocale('de-DE').useViewStrategy(ValidateCustomAttributeViewStrategy.TWBootstrapAppendToInput); });

aurelia.start().then(a => a.setRoot('app', document.body));
}

I alway get the following error message:

Unhandled promise rejection ReferenceError: ValidateCustomAttributeViewStrategy is not defined

What am I doing wrong?

Pavier answered 2/7, 2015 at 14:14 Comment(0)
I
3

Add import {ValidateCustomAttributeViewStrategy} from 'aurelia-validation'; to the top of your file

Intergrade answered 3/7, 2015 at 12:42 Comment(1)
Thanks, that works! I figured it would be something simple, but I didn't come up with it.Pavier
A
8

Looks like this just recently changed. So as of 10/12/2015 this works:

import { TWBootstrapViewStrategy } from 'aurelia-validation';
...

export function configure(aurelia) {
    aurelia.use
        .plugin('aurelia-validation', (config) => config
           .useViewStrategy(TWBootstrapViewStrategy.AppendToInput))
        ...
}

As an aside, the d.ts is currently missing the definitions for the strategies so if you're using TypeScript you'll have to cast the strategy to any:

import { ValidationConfig, TWBootstrapViewStrategy } from 'aurelia-validation';
...

export function configure(aurelia: Aurelia) {
    aurelia.use
        .plugin('aurelia-validation', (config: ValidationConfig) => config
            .useViewStrategy((<any>TWBootstrapViewStrategy).AppendToInput))
        ...
}
Achaea answered 12/10, 2015 at 20:8 Comment(0)
I
3

Add import {ValidateCustomAttributeViewStrategy} from 'aurelia-validation'; to the top of your file

Intergrade answered 3/7, 2015 at 12:42 Comment(1)
Thanks, that works! I figured it would be something simple, but I didn't come up with it.Pavier
A
0

For aurelia validation version 1.0. It works with creating a custom renderer. See it here on section custom renderers.

Aude answered 28/6, 2017 at 3:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.