当前位置: 动力学知识库 > 问答 > 编程问答 >

aurelia - Custom Element validation

问题描述:

I have a custom element (a partial URL) called @customElement('partialurl')

partialurl.js

get isValid(){

if (this.element === undefined || this.element === null){

return false;

}

else{

const partialUrl = new RegExp('^\/[a-z0-9]+([-\/](?:[a-z0-9]+))*(\.(?:jpeg|jpg|gif|png|htm|html|asp|xml|txt|pdf))?$');

if (partialUrl.test(this.element)) {

return true;

} else {

return false;

}

}

}

My question is how do I reference the 'isValid'?

For example - this file references the custom element

html

<partialurl disabled.bind="readonly" value.bind="baseContent.LinkDestination" />

js

bind(){

return this.dataContext.getContent(this.id)

.then(baseContent => {

this.baseContent = baseContent;

this.validator = this.validation.on(this)

.ensure('baseContent.LinkDestination').isValidFromCustomElement();

}); }

I know the above doesn't work, I am new to Aurelia and still finding my feet with it.

分享给朋友:
您可能感兴趣的文章:
随机阅读: