ng2-tree
ng2-tree copied to clipboard
Enforce file naming restriction
How can I implement the enforcement of file names, lets say I want the user to only choose file names that start with a capital letter, contain only letters and end with an extension (.ss.src). I want to give the user a visual feedback when he enters a wrong file name. example of file names:
- file.txt (refuse)
- File.ss.src (accept)
Tried: capture the event in the handleCreated()
, checked the file name against some RegEx if the test fails I simply breaks with return;
Problem is: when the file name is typed, the user can type anything, hits entre, and the tree display the file anyway, even if I broke early in the function.
here is pseudocode
handleCreated(event) {
if (event.node.value doesn't match /some RegEx/) {
return;
} else {
saveToDb(event.node.value);
}
}
How can I prevent the tree from accepting the newly created file if it doesn't match the RegEx ?
@amirhakim Could you please, provide a bit more details, perhaps with examples? Because I haven't fully got your issue - the description is very laconic.
I think I understand what he is asking for... He wants to be able to validate name changes before they are applied. For instance, if the node names represent file system names, certain characters are not allowed.
@indywill Now I see, thanks!
any update on this ?