Skip to content
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

Add custom validation code #89

Closed
jmetz opened this issue Oct 22, 2023 · 2 comments · Fixed by #91
Closed

Add custom validation code #89

jmetz opened this issue Oct 22, 2023 · 2 comments · Fixed by #91
Labels
enhancement New feature or request

Comments

@jmetz
Copy link

jmetz commented Oct 22, 2023

Would likely go in addTag, and passed in as an optional function:

function addTag(currentTag) {
if (typeof currentTag === 'object' && currentTag !== null) {
if (!autoCompleteKey) {
return console.error("'autoCompleteKey' is necessary if 'autoComplete' result is an array of objects");
}
if (onlyUnique) {
let found = tags?.find(elem => elem[autoCompleteKey] === currentTag[autoCompleteKey]);
if (found) return;
}
var currentObjTags = currentTag;
currentTag = currentTag[autoCompleteKey].trim();
} else {
currentTag = currentTag.trim();
}
if (currentTag == "") return;
if (maxTags && tags.length == maxTags) return;
if (onlyUnique && tags.includes(currentTag)) return;
if (onlyAutocomplete && arrelementsmatch.length === 0) return;
tags.push(currentObjTags ? currentObjTags : currentTag)
tags = tags;
tag = "";
// Hide autocomplete list
// Focus on svelte tags input
arrelementsmatch = [];
autoCompleteIndex = -1;
document.getElementById(id).focus();
if (maxTags && tags.length == maxTags) {
document.getElementById(id).readOnly = true;
placeholder = "";
};
}

@jmetz jmetz changed the title Add custom validation code - would likely Add custom validation code Oct 22, 2023
@jmetz
Copy link
Author

jmetz commented Oct 22, 2023

Note: I've been trying to add custom outer validation to no avail; when I change tags (which is bound to your component) in the parent component within a reactive block, that change doesn't get reflected in the tags displayed in your component.

@agustinl agustinl added the enhancement New feature or request label Jan 18, 2024
@agustinl agustinl mentioned this issue Jan 18, 2024
@agustinl agustinl linked a pull request Jan 18, 2024 that will close this issue
@agustinl
Copy link
Owner

agustinl commented Jan 18, 2024

Hiii

  • Add: customValidation prop. 👐🏻 in next release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants