export class CustomValidationRule extends ValidationRule {
constructor(threshold) {
super(
...
);
}
}
ValidationGroupBuilder.prototype['prcbIsNumber'] = function () {
return this.passesRule(new CustomValidationRule());
}
ValidationGroup.prototype['prcbIsNumber'] = function () {
return this.builder.prcbIsNumber();
};
it will will be nice we can call it with statement like this
this.validation.on(this.country, undefined).ensure('CSTLCNTRY').prcbIsNumber()
// but this is not possible now
// I need to cast it to any to be able to do that
(<any>this.validation.on(this.country, undefined)).ensure('CSTLCNTRY').prcbIsNumber()
there is solution but I need to rewrite aurelia-validation.d.ts every time when it is published
declare module 'aurelia-validation/validation/validation-group' {
/**
* Encapsulates validation rules and their current validation state for a given subject
* @class ValidationGroup
* @constructor
*/
export interface IValidationGroup {
// ...
/**
* Instantiates a new {ValidationGroup}
* @param subject The subject to evaluate
* @param observerLocator The observerLocator used to monitor changes on the subject
* @param config The configuration
*/
new(subject: any, observerLocator: any, config: any);
// ...
/**
* Specifies that the execution of the previous validation rule should use the specified error message if it fails
* @param message either a static string or a function that takes two arguments: newValue (the value that has been evaluated) and threshold.
* @returns {ValidationGroup} returns this ValidationGroup, to enable fluent API
*/
withMessage(message: any): any;
}
export var ValidationGroup : IValidationGroup;
}
Hi,
If I create custom validation rule, like this
it will will be nice we can call it with statement like this
there is solution but I need to rewrite aurelia-validation.d.ts every time when it is published
then I can define my validation.d.ts
links:
http://stackoverflow.com/questions/23217334/how-do-i-extend-a-typescript-class-definition-in-a-separate-definition-file
https://github.com/Microsoft/TypeScript/issues/819