@@ -232,6 +232,52 @@ The function `validateFilledFieldsWithValidationRules` us really useful as you c
232232
233233The function ` controllerValidByRules ` will check if a validation controller is valid.
234234
235+ This could be an example implementation
236+ ```
237+ class FormExample {
238+
239+ @bindable({ defaultBindingMode: bindingMode.twoWay }) public user: User;
240+
241+ private controller: ValidationController;
242+ private rules: Rule<CustomerContactRestModel, any>[][];
243+
244+ public constructor(
245+ private validationControllerFactory: ValidationControllerFactory
246+ ) {
247+ this.controller = this.validationControllerFactory.createForCurrentScope();
248+ this.controller.validateTrigger = validateTrigger.changeOrBlur;
249+ }
250+
251+ public bind(): void {
252+ this.setupValidationRules();
253+ validateFilledFieldsWithValidationRules(this.rules, this.user, this.controller);
254+ }
255+
256+ @computedFrom('user')
257+ public get isValid(): boolean {
258+ return controllerValidByRules(this.rules, this.user, this.controller);
259+ }
260+
261+ private setupValidationRules(): void {
262+ this.rules = ValidationRules
263+ .ensure((user: User) => user.lastName)
264+ .displayName('USER.LAST_NAME')
265+ .required()
266+ .ensure((user: User) => user.email)
267+ .displayName('USER.EMAIL')
268+ .email()
269+ .on(this.customerContact).rules;
270+ }
271+ }
272+ ```
273+
274+ ### i18n integration
275+ You can pass a tranlation string into the ` displayName('USER.LAST_NAME') ` and it will be translated for you.
276+
277+ Additionally you can translate methods like ` .required() ` in ` src/local/* ` as demostrated in the files.
278+
279+ If you use the the method ` withMessageKey('YOUR.TRANSLATION') ` you can pass a translation string and it will be translated for you.
280+
235281## Route generator service
236282If you have router tree like this
237283```
0 commit comments