hailwood / jQuery-Tagit

The Jquery Tagit Plugin transforms an html unordered list into a unique tagging plugin.
264 stars 109 forks source link

Select not included in form when clearing tags #83

Open louis opened 11 years ago

louis commented 11 years ago

Hi everyone,

I just ran into an issue with tagit that excludes the select form element from being submitted when clearing a previously entered tag list. Has anyone else seen this issue? If so I'm curious to see the workaround. In the meantime I'll share mine below:

tagsChanged: function(tagValue, action, element) {
    var tags = TFW.widget.Tag.getTags($("#"+tagListContainer).tagit("tags"));
    if ($.isEmpty(tags)) {
        $("select[name='"+tagFormInputField+"']").append('<option selected="selected" value=""></option>');
    }
}

In a nutshell I'm simply adding an empty select option if the tag list has been cleared. Also, there's a bit of my own code such as $.isEmpty, which checks for empty string, and TFW.widget.Tag.getTags, which simply retrieves the tag list.

Thanks!