client/tags: improve tag regex handling
This commit is contained in:
parent
2f20bc1619
commit
7b4645b54b
1 changed files with 26 additions and 2 deletions
|
@ -17,12 +17,15 @@ class TagEditView extends events.EventTarget {
|
|||
|
||||
this._tag = ctx.tag;
|
||||
this._hostNode = ctx.hostNode;
|
||||
const baseRegex = config.tagNameRegex.replace(/[\^\$]/g, '');
|
||||
ctx.tagNamesPattern = '^((' + baseRegex + ')\\s+)*(' + baseRegex + ')$';
|
||||
views.replaceContent(this._hostNode, template(ctx));
|
||||
|
||||
views.decorateValidator(this._formNode);
|
||||
|
||||
if (this._namesFieldNode) {
|
||||
this._namesFieldNode.addEventListener(
|
||||
'input', e => this._evtNameInput(e));
|
||||
}
|
||||
|
||||
if (this._implicationsFieldNode) {
|
||||
new TagInputControl(this._implicationsFieldNode);
|
||||
}
|
||||
|
@ -53,6 +56,27 @@ class TagEditView extends events.EventTarget {
|
|||
views.showError(this._hostNode, message);
|
||||
}
|
||||
|
||||
_evtNameInput(e) {
|
||||
const regex = new RegExp(config.tagNameRegex);
|
||||
const list = this._namesFieldNode.value.split(/\s+/).filter(t => t);
|
||||
|
||||
if (!list.length) {
|
||||
this._namesFieldNode.setCustomValidity(
|
||||
'Tags must have at least one name.');
|
||||
return;
|
||||
}
|
||||
|
||||
for (let item of list) {
|
||||
if (!regex.test(item)) {
|
||||
this._namesFieldNode.setCustomValidity(
|
||||
`Tag name "${item}" contains invalid symbols.`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this._namesFieldNode.setCustomValidity('');
|
||||
}
|
||||
|
||||
_evtSubmit(e) {
|
||||
e.preventDefault();
|
||||
this.dispatchEvent(new CustomEvent('submit', {
|
||||
|
|
Loading…
Reference in a new issue