BindingEngine in a nodejs application

Update: Created new topic at Aurelia-validation plugin in NodeJs

It’s been a little while since I worked on this. Practically a year ago. I’m finally revisiting this and I made progress but I’m now getting an error due to the way I’m trying to share code between the web and the server. I’m getting the friendly message ’ Did you forget to add “.plugin(‘aurelia-validation’)” to your main.js?’ How can I make that work in a node project? My code is actually running correctly up to this point if I pass in something that does not require validation.

(node:18088) UnhandledPromiseRejectionWarning: Error: Did you forget to add ".plugin('aurelia-validation')" to your main.js?
    at FluentEnsure.assertInitialized (C:\source\control_set\node_modules\aurelia-validation\dist\commonjs\aurelia-validation.js:1779:15)
    at FluentEnsure.ensure (C:\source\control_set\node_modules\aurelia-validation\dist\commonjs\aurelia-validation.js:1744:14)
    at Function.ValidationRules.ensure (C:\source\control_set\node_modules\aurelia-validation\dist\commonjs\aurelia-validation.js:1812:58)

My rules are defined as such

            ValidationRules.ensure((c: StringControlConfiguration) => c.value)
                .required()
                .when(() => control.validation.required && control.canValidate)
                .withMessage(`${control.label || control.placeholder} is required`)
                .satisfies((value: string) => {
                    return value !== null ? value.indexOf(control.promptChar) === -1 : true;
                })
                .when(() => control.mask !== null && control.promptChar !== null && control.canValidate)
                .withMessage(`${control.label || control.placeholder} does not meet the format: ${control.mask}`)
                .matches(control.validation.regEx)
                .when(() => control.validation.regEx !== null && control.canValidate)
                .withMessage(`${control.label || control.placeholder} is invalid (${control.validation.regEx})`)
                .satisfies(control.isValidRegEx)
                .when(() => control.inputType === 'regularExpression' && control.canValidate)
                .withMessage(`${control.label || control.placeholder} is not a valid regular expression`)
                .maxLength(control.validation.maxLength)
                .when(() => control.validation.maxLength !== null && control.canValidate)
                .withMessage(
                    `${control.label || control.placeholder} must be less than ${
                        control.validation.maxLength
                    } characters`
                )
                .minLength(control.validation.minLength)
                .when(() => control.validation.minLength !== null && control.canValidate)
                .withMessage(
                    `${control.label || control.placeholder} must be greater than ${
                        control.validation.minLength
                    } characters`
                ).satisfies((value: string) => {
                    return value !==null ? !control.validation.restrictedValues.some((x) => x.toLowerCase() === value.toLowerCase()): true
                })
                .when(() => control.validation.restrictedValues !== null)
                .withMessage(`${control.label || control.placeholder || "Input"} cannot contain the current value`)
                .on(control);
1 Like