|
25 | 25 |
|
26 | 26 | value = jQuery.trim(value); |
27 | 27 |
|
28 | | - if ((options.unique && $(this).tagExist(value)) || !_validateTag(value, options, tagslist)) { |
| 28 | + if ((options.unique && $(this).tagExist(value)) || !_validateTag(value, options, tagslist, delimiter[id])) { |
29 | 29 | $('#' + id + '_tag').addClass('error'); |
30 | 30 | return false; |
31 | 31 | } |
|
172 | 172 | if (!settings.interactive) return this; |
173 | 173 |
|
174 | 174 | $(data.fake_input).val(''); |
| 175 | + $(data.fake_input).data('pasted', false); |
175 | 176 |
|
176 | 177 | $(data.holder).on('click', data, function(event) { |
177 | 178 | $(event.data.fake_input).focus(); |
|
180 | 181 |
|
181 | 182 | $(data.fake_input).on('focus', data, function(event) { |
182 | 183 | $(data.holder).addClass('focus'); |
| 184 | + if ($(this).val() === '') { |
| 185 | + $(this).removeClass('error'); |
| 186 | + } |
183 | 187 | }); |
184 | 188 |
|
185 | 189 | $(data.fake_input).on('blur', data, function(event) { |
|
237 | 241 | }); |
238 | 242 | } |
239 | 243 |
|
240 | | - // TODO: keypress and input cannot interfere with each other (look at validation perspective also) |
241 | | - |
242 | 244 | // If a user types a delimiter create a new tag |
243 | 245 | $(data.fake_input).on('keypress', data, function(event) { |
244 | 246 | if (_checkDelimiter(event)) { |
|
257 | 259 | } |
258 | 260 | }); |
259 | 261 |
|
| 262 | + $(data.fake_input).on('paste', function () { |
| 263 | + $(this).data('pasted', true); |
| 264 | + }); |
| 265 | + |
260 | 266 | // If a user pastes the text check if it shouldn't be splitted into tags |
261 | | - $(data.fake_input).bind('input', data, function(event) { |
| 267 | + $(data.fake_input).on('input', data, function(event) { |
| 268 | + if (!$(this).data('pasted')) return; |
| 269 | + |
| 270 | + $(this).data('pasted', false); |
| 271 | + |
262 | 272 | var value = $(event.data.fake_input).val(); |
263 | 273 |
|
264 | 274 | value = value.replace(/\n/g, ''); |
|
292 | 302 | $(this).trigger('focus'); |
293 | 303 | } |
294 | 304 | }); |
295 | | - |
296 | | - $(data.fake_input).blur(); |
297 | 305 |
|
298 | 306 | // Removes the error class when user changes the value of the fake input |
299 | | - if (data.unique) { |
300 | | - $(data.fake_input).keydown(function(event) { |
| 307 | + $(data.fake_input).keydown(function(event) { |
| 308 | + console.log('?'); |
| 309 | + // alt, shift, esc, ctrl and arrows keys are not taken into consideration |
| 310 | + // if (!$.inArray(event.keyCode, [37, 38, 39, 40, 27, 16, 17, 225])) { |
301 | 311 | $(this).removeClass('error'); |
302 | | - }); |
303 | | - } |
| 312 | + // } |
| 313 | + }); |
304 | 314 | }); |
305 | 315 |
|
306 | 316 | return this; |
|
344 | 354 | } |
345 | 355 | }; |
346 | 356 |
|
347 | | - var _validateTag = function(value, options, tagslist) { |
| 357 | + var _validateTag = function(value, options, tagslist, delimiter) { |
348 | 358 | var result = true; |
349 | 359 |
|
350 | 360 | if (value === '') result = false; |
|
353 | 363 | if (options.limit !== null && tagslist.length >= options.limit) result = false; |
354 | 364 | if (options.validationPattern !== null && !options.validationPattern.test(value)) result = false; |
355 | 365 |
|
| 366 | + if (typeof delimiter === 'string') { |
| 367 | + if (value.indexOf(delimiter) > -1) result = false; |
| 368 | + } else { |
| 369 | + $.each(delimiter, function(index, _delimiter) { |
| 370 | + if (value.indexOf(_delimiter) > -1) result = false; |
| 371 | + return false; |
| 372 | + }); |
| 373 | + } |
| 374 | + |
356 | 375 | return result; |
357 | 376 | }; |
358 | 377 |
|
|
0 commit comments