Skip to content

Commit 6b77eb0

Browse files
committed
#6: limit func.
1 parent 2ce9ca4 commit 6b77eb0

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/jquery.tagsinput-revisited.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
value = jQuery.trim(value);
2727

28-
if ((options.unique && $(this).tagExist(value)) || !_validateTag(value, options)) {
28+
if ((options.unique && $(this).tagExist(value)) || !_validateTag(value, options, tagslist)) {
2929
$('#' + id + '_tag').addClass('error');
3030
return false;
3131
}
@@ -109,6 +109,7 @@
109109
placeholder: 'Add a tag',
110110
minChars: 0,
111111
maxChars: null,
112+
limit: null,
112113
width: 'auto',
113114
height: 'auto',
114115
autocomplete: {selectFirst: false},
@@ -194,7 +195,8 @@
194195
focus: true,
195196
unique: settings.unique,
196197
minChars: settings.minChars,
197-
maxChars: settings.maxChars
198+
maxChars: settings.maxChars,
199+
limit: settings.limit
198200
});
199201
}
200202
});
@@ -205,7 +207,8 @@
205207
focus: true,
206208
unique: settings.unique,
207209
minChars: settings.minChars,
208-
maxChars: settings.maxChars
210+
maxChars: settings.maxChars,
211+
limit: settings.limit
209212
});
210213

211214
return false;
@@ -217,7 +220,8 @@
217220
focus: true,
218221
unique: settings.unique,
219222
minChars: settings.minChars,
220-
maxChars: settings.maxChars
223+
maxChars: settings.maxChars,
224+
limit: settings.limit
221225
});
222226

223227
return false;
@@ -233,7 +237,8 @@
233237
focus: true,
234238
unique: settings.unique,
235239
minChars: settings.minChars,
236-
maxChars: settings.maxChars
240+
maxChars: settings.maxChars,
241+
limit: settings.limit
237242
});
238243

239244
return false;
@@ -280,7 +285,8 @@
280285
focus: false,
281286
callback: false,
282287
minChars: 0,
283-
maxChars: null
288+
maxChars: null,
289+
limit: null
284290
});
285291
}
286292

@@ -290,12 +296,13 @@
290296
}
291297
};
292298

293-
var _validateTag = function(value, options) {
299+
var _validateTag = function(value, options, tagslist) {
294300
var result = true;
295301

296302
if (value === '') result = false;
297303
if (value.length < options.minChars) result = false;
298304
if (options.maxChars !== null && value.length > options.maxChars) result = false;
305+
if (options.limit !== null && tagslist.length >= options.limit) result = false;
299306

300307
return result;
301308
};

0 commit comments

Comments
 (0)