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

Unable to get ID of new tag to submit with 'on' #1385

Open
cary42 opened this issue Oct 1, 2024 · 0 comments
Open

Unable to get ID of new tag to submit with 'on' #1385

cary42 opened this issue Oct 1, 2024 · 0 comments

Comments

@cary42
Copy link

cary42 commented Oct 1, 2024

When adding a new tag I send it via ajax and get back an ID. If I then select another tag, it sends the data via ajax again but the value for that new ID is empty. I'm not sure I'm adding the tag right.

The data.id value is printed to the console and is correct so I'm submitting it to addTags() and the form data on the next submit looks like:
ids[]: 245290
ids[]: 245289
ids[]:
ids[]: 245283

function sendAllTagIds(e) {
    const tagElements = tagify.getTagElms();
    const tagIds = tagElements.map(tag => tag.getAttribute('id'));
    const value = e.detail.data.value;

    $.post('/action/add-tag.php', { ids: tagIds })
    .done(function(response) {
        var data = JSON.parse(response);
        if(data.success) {
            tagify.settings.whitelist.push(data.value);

            // Only add the new tag if the new_tag_id exists
            var id = data.id;

            console.log('New tag ID:', id);
            if (id) {
                tagify.addTags([{ value: value, id: id }]);
            }
        } else {
            warn(data.message);
        }
    })
    .fail(function(jqXHR, textStatus, errorThrown) {
        console.error('Error updating tags:', textStatus, errorThrown);
    });
}

Any help appreciated. Thanks.

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

No branches or pull requests

1 participant