Reputation: 1155
I am trying to work out how I would do a startsWith? This is a custom element, it needs to validate that the string starts with a "\"
<template>
<input disabled.bind="readonly" type="text" class="form-control" value.bind="value">
</template>
import {customElement, bindable, inject, bindingMode} from 'aurelia-framework';
import {activationStrategy} from 'aurelia-router';
import $ from 'jquery';
import {Validation} from 'aurelia-validation';
@customElement('url')
@bindable({name: 'value', attribute: 'value', defaultValue: '', defaultBindingMode: bindingMode.twoWay})
@bindable({name: 'readonly', attribute: 'disabled', defaultValue: false, defaultBindingMode: bindingMode.oneWay})
@inject(Element, Validation)
export class Url {
constructor(element, validation) {
this.element = element;
this.validation = validation.on(this)
.ensure(this.element)
.isNotEmpty()
.containsNoSpaces()
.matches('/^[\].*/');
}
bind(){
$('.input', this.element).val(this.value);
if(this.readonly){
$('.input', this.element).attr('readonly', 'readonly');
}
}
}
I've looked at http://aurelia.io/validation/#/logical-operators and I think Im doing it right but it throws an error: inner error: TypeError: path.split is not a function
Upvotes: 0
Views: 1540
Reputation: 35134
ensure()
accepts the name of validated field, not the element It should be something like
this.validation = validation.on(this)
.ensure('value')
.isNotEmpty()
.containsNoSpaces()
.matches(/^\\.*$/);
Upvotes: 3