-
I have an existing Aurelia v1 website - https://david.gardiner.net.au/azure-resource-namer/ that I'm working on converting to v2. The current v1 implementation includes validation on the value displayed in the 'resource name' field. The resource name is a composite of the other fields on the page, but the validation only makes sense to be applied to this value. eg. I am trying to figure out how to achieve something similar with v2. I've tried using the new validator and pointing it at the 'resourcename' property but it doesn't seem to work (also including using Is this supported to validate a 'computed' property, or is there an alternate approach that I could use? Code from my-app.ts constructor(
@newInstanceForScope(IValidationController) private validationController: IValidationController,
@IValidationRules validationRules: IValidationRules
) {
this.copyIcon = faCopy;
this.copiedIcon = faCheckSquare;
this.copied = false;
this.instance = 1;
this.environment = "prod";
this.workload = "myapp";
this.message = "msg";
this.region = 'westus';
this.selectedResource = { abbrev: 'rg', name: ''};
this.thingy = 'ah';
this.resourceNameValid = true;
validationRules.on(this)
.ensure('resourceName')
.required()
.maxLength(10);
}
get resourceName(): string {
return formatResourceName(this.selectedResource, this.workload, this.environment, this.region, this.instance, this);
} code from my-app.html <input id="resourceName" type="text" class="form-control has-validation" value.bind="resourceName & validate"
aria-multiline="false" readonly="" spellcheck="false" tabindex="-1" aria-readonly="true"
title="resource name" required> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @flcdrg, here is a working example for you, if it helps: |
Beta Was this translation helpful? Give feedback.
I have updated the example. It needed
Note that the
validate
binding behaviour is intentionally designed in such a way that it delays the validation feedback to reduce the cognitive load of the user and in turn offers better UX. Roughly speaking, the event based validations are not triggered, if a field is not touched and/or dirty. If the validation is "forced" via theValidationController#validate
, only then all the fields and objects registered with the controller gets validated.