-
Notifications
You must be signed in to change notification settings - Fork 69
improvements suggestions #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is helpful, thanks. I was looking for a way to do input validation, and this gets me off to a good start. Your code doesn't seem to handle the case of editing a tag, however. I added the following to the var tagString = textfield.val().replace(/\s{2,}/g, ' ');
if ((tagString === ' ') ||
(tagRegexp.test(tagString) === false)) {
textfield.val('');
} Thanks! |
I added the following to disallow the user from entering characters which don't match the regex: function isIllegalCharacter(characterCode) {
return tagRegexp.test(String.fromCharCode(characterCode)) === false
} I then call that function in the two .keypress(function(event) {
var code = event.keyCode > 0 ? event.keyCode : event.which;
if ($.inArray(code, options.breakKeyCodes) > -1) {
if ($(this).val().length > 0 && $('ul.ui-autocomplete #ui-active-menuitem').length == 0) {
$(this).trigger('transformToTag');
}
event.preventDefault();
return false;
} else if (isIllegalCharacter(code)) {
event.preventDefault();
return false;
}
return true;
}) .keypress(function(event) {
switch (event.keyCode) {
case 13: // RETURN
event.preventDefault();
$(this).parent().trigger('finishEdit');
return false;
case 27: // ESC
event.preventDefault();
$(this).parent().trigger('finishEdit', [true]);
return false;
default:
// swallow invalid characters
var code = event.keyCode > 0 ? event.keyCode : event.which;
if (isIllegalCharacter(code)) {
event.preventDefault();
return false;
}
}
return true;
}) You'll of course want to do the regex check on the server side as well since this is purely UI gravy that any sufficiently savvy user could circumvent. Chris |
Yeah I don't allow tag editing in my project so that's why I missed it! I tried to do what you suggest before but I haven't been able to prevent carets (^) from being typed or being used as diacritics (âô). I haven't been looking thoroughly into this issue though. If you find a way to do this, I would be interested :) Some other things that could be done to improve this plugin:
else if (typeof options.autocompleteOptions.source === "string") {
// Check also autocomplete values
var autocompleteURL = options.autocompleteOptions.source;
if (autocompleteURL.match(/\?/)) {
autocompleteURL += '&';
} else {
autocompleteURL += '?';
}
autocompleteURL += 'term=' + value;
$.ajax({
async: false,
url: autocompleteURL,
dataType: 'json',
complete: function (XMLHttpRequest, textStatus) {
result = $.parseJSON(XMLHttpRequest.responseText);
});
}
// close autocomplete
if(options.autocompleteOptions.source) {
$(this).autocomplete( "close" );
} The purpose of this, I guess, is to close the autocomplete list when you input a tag so, when you start typing again after the input has been cleared it shows up at the new input position.
|
drenty said:
They key press event handler modifications I posted earlier prevent the caret from being typed, as long as your regex doesn't allow them. I'm using In short, it all just works. Chris |
Does anyone of you can do a pull request with the changes? |
I missed your reply. If it's still relevant I can do that. |
I've tweaked Tagedit a little bit for my own needs, here is what I came up with:
New features:
Bug fix:
What could be done:
I have other improvements in my mind, but it needs more thinking. Tell me what you think!
Here is the diff with the version I'm using on my project:
The text was updated successfully, but these errors were encountered: