locked
how to get tags from tag-it RRS feed

  • Question

  • User-1693623980 posted

    hi,

    I want to use tag-it jquery  UI plugin for adding tags in my asp.net mvc application.

    this is the link of plugin

    https://github.com/aehlke/tag-it

    this is html

    <div class="form-group">
                @Html.LabelFor(model => model.Tags, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                   
    
                    <ul id="TagsUl">
                        
                       
                    </ul>
                    <label id="Tags"></label>
                </div>
            </div>

    I want to get tags array from #TagsUl and convert the array to string and assign this string to #Tags label

    so this is jquery code but it doesn't work, I mean after add each tag label #Tags is empty

    <script type="text/javascript">
        $(document).ready(function () {
            $("#TagsUl").tagit({
                afterTagAdded: function (event, ui) {
                    // do something special
                    //console.log(ui.tag);
                    $("#Tags").text = ($("#TagsUl").assignedTags()).toString();
                }
            });
            
        });
        
    
    </script>

    I inspect the page after adding two tags, as you can see in picture below li tags created successfully but label is empty!

    could you please help?

    Friday, June 24, 2016 4:35 PM

Answers

  • User2103319870 posted

    Your code should give your a comma separated list of values. Most likely the issue will be your array has not been populated with multiple values.

    Please check to ensure your array is having multiple values

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 24, 2016 6:12 PM

All replies

  • User2103319870 posted

    I inspect the page after adding two tags, as you can see in picture below li tags created successfully but label is empty!

    Try assigning value to label like below

    <script type="text/javascript">
            $(document).ready(function () {
                $("#TagsUl").tagit({
                    afterTagAdded: function (event, ui) {
                        // do something special
                        //console.log(ui.tag);
                        $("#Tags").text($("#TagsUl").assignedTags().toString());
                    }
                });
    
            });
        </script>

    Friday, June 24, 2016 4:52 PM
  • User-1693623980 posted

    thanks a2h,

    I test it, but the problem is the same, although the label in inspect is empty but i found the first item inserted in database,

    so first item of array assign to label.

    but I need a string of tags like this:   test1,test2

    Friday, June 24, 2016 5:57 PM
  • User2103319870 posted

    Your code should give your a comma separated list of values. Most likely the issue will be your array has not been populated with multiple values.

    Please check to ensure your array is having multiple values

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 24, 2016 6:12 PM
  • User-1693623980 posted

    thaaaaaaaaaaaaaaaaaaanks,

    you are right,

    I added this code and it worked!

    singleField:true,
    Friday, June 24, 2016 6:36 PM