ng2-tree icon indicating copy to clipboard operation
ng2-tree copied to clipboard

Enforce file naming restriction

Open amirhakim opened this issue 7 years ago • 4 comments

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 avatar Oct 24 '17 18:10 amirhakim

@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.

rychkog avatar Oct 28 '17 13:10 rychkog

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 avatar Jan 01 '18 20:01 indywill

@indywill Now I see, thanks!

rychkog avatar Feb 05 '18 08:02 rychkog

any update on this ?

Dhamu143 avatar Apr 06 '18 13:04 Dhamu143