I am using the Select2 library to create tags and what I would like is to limit the length of the characters of the tags in my input. For example:
I would like to limit it to 10 characters.
If the user enters "apple" , the tag would be created since it has a length of 7 characters
But if the user enters: "parallelepipedo" , then the tag should not be created in the input since it exceeds 10 characters (the word has 12 characters)
This is my jquery code for my select2 and it works perfectly, however I want the user not to put such a long word to create tags.
$("#customer_tag_ids").select2({
maximumSelectionLength: 5,
multiple: true,
tags: true,
createTag: function (params) {
if (params.term.match(/^(?![\d ])[a-z\d ]*$/i)) {
// Return null to disable tag creation
return {
id: params.term,
text: params.term,
tag: true
}
}
return null;
},
language: {
maximumSelected: function (e) {
return I18n.t('customer.alert.limit_max');
},
inputTooShort: function (e) {
return I18n.t('customer.alert.limit_min');
},
noResults: function(){
return I18n.t('customer.alert.not_result_found');
}
},
});
If anyone knows and can help me I would be very grateful.
Happy day.