[CLOSED] TagField : How to allow duplicate Tag in TagField

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] TagField : How to allow duplicate Tag in TagField

    Hi I have a (,) separated string like bellow,
    a,+,b,+,c,-,d,*e
    and now I try to this in a tag,for this I use bellow code
    string s="a,+,b,+,c,-,d,*e";
    string[] rawformula = s.Split(',');
    Tags t = new Tags();
    foreach (string s in rawformula)
                {
                   t.Add(new Tag(s));
    }
    TagField tf = this.GetCmp<TagField>("tag");
                tf.Clear();
                tf.SetRawValue(t);
    and when displayed in tagfield it will show only one (+) .
    please assist me how to display duplicate tag in tagfield with above approach.

    I am doing this because ,bellow code not working
    string s="a,+,b,+,c,-,d,*e";
    string[] rawformula = s.Split(',');
    foreach (string s in rawformula)
                {
                    
                 
                    data.Add(new { Formula = s});
                    
                }
                var tagStore = X.GetCmp<Store>("tagStore");
                            tagStore.LoadData(data);
               
                return this.Direct();



    X.TagField()
                                .ID("tag")
                                .HideSelected(true)
                                .Width(375)
    
                                .HideTrigger(true)
                                .Editable(true)
                                .DisplayField("Formula")
                                .ValueField("Formula")
                                .MultiSelect(true)
                                
                                .Store(X.Store()
                                .ID("tagStore")
    
                                .Model(X.Model()
                                    .Fields(
                                            Html.X().ModelField().Name("Formula").Type(ModelFieldType.String)
                                            
                                    )
                                )
                             
                            )
    Last edited by Daniil; Dec 31, 2014 at 1:51 PM. Reason: [CLOSED]
  2. #2
    Hi @matrixwebtech,

    I would try this.
    @(Html.X().TagField()
        .TagLabelConfig(X.TagLabel()
            .AllowDuplicates(true)
        )
    )
    If it doesn't work for you, please provide a full test case.
  3. #3
    Hi daniil thanks for reply.
    If it doesn't work for you, please provide a full test case.
    your assumption is correct.bellow is the test case.
    View
    @X.ResourceManager()
           @( X.TagField()
            .ID("tag")
            .HideSelected(true)
            .Width(375)
    
            .HideTrigger(true)
            .Editable(true)
            .DisplayField("Formula")
            .ValueField("Formula")
            .MultiSelect(true)
            .DirectEvents(de =>
                        {
                            de.AfterRender.Action = "populatetag";
                        })
           
            .TagLabelConfig(X.TagLabel()
            .AllowDuplicates(true)                       
                    .Listeners(events =>
                        events.TagRemove.Handler = "alert('TagRemove');"
                        )
            )
            .Store(X.Store()
            .ID("tagStore")
    
            .Model(X.Model()
            .Fields(
            Html.X().ModelField().Name("Formula").Type(ModelFieldType.String)
            
            )
            )
           
            )
            )
    Controller

     public class tagfieldallowduplicateController : Controller
        {
            //
            // GET: /tagfieldallowduplicate/
    
            public ActionResult Index()
            {
               
                return View();
            }
            public ActionResult populatetag()
            {
                string s = "a,+,b,+,c,-,d,*,e";
                string[] rawformula = s.Split(',');
                Tags t = new Tags();
                foreach (string s1 in rawformula)
                {
                    t.Add(new Tag(s1));
                }
                TagField tf = this.GetCmp<TagField>("tag");
                tf.Clear();
                tf.SetValue(t);
                return this.Direct();
            }
    
        }
    Last edited by matrixwebtech; Dec 29, 2014 at 12:20 PM.
  4. #4
    Thank you for the test case.

    The .AllowDuplicates(true) setting deals with Tags' text. Values of tags must be unique still.

    If you create a tag like this:
    new Tag(s1)
    It means that the Tag's Value will be equal to its Text.

    So, you won't be able to add one Tag more with the same Text, because it automatically means that there will be two Tags with the same Values, that is not allowed.

    I see there is the only way - specify some unique Value explicitly for each Tag. Something like that:
    int i = 0;
    
    foreach (string s1 in rawformula)
    {
        t.Add(new Tag() { Text = s1, Value = i++.ToString() });
    }
  5. #5
    Hi daniil as per your suggesstion I fix this from code ,now I need your help to do this from javascript.
    I try bellow but
     App.tag.addItem('k', 1)
    not working
      App.tag.addTag('k1')
    working but I cannot add duplicate tag .
    <script>
    
            var populateTag = function () {
                console.log(App.tag)
                App.tag.addItem('k', 1)//this is not work
                App.tag.addTag('k1')
            }
    
        </script>
    
            @X.ResourceManager()
            @(X.TagField()
                .ID("tag")
                .HideSelected(true)
                .Width(800)
               
                .HideTrigger(true)
                .Editable(true)
               .TagLabelConfig(X.TagLabel().AllowDuplicates(true))
                .MultiSelect(true)
                )
            @(X.Button().Text("Click")
    .Listeners(l =>
    {
        l.Click.Fn = "populateTag";
    })
    )
  6. #6
    Workaround:

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        [DirectMethod]
        public void AddTags()
        {
            string[] rawformula = "a,+,b,+,c,-,d,*e".Split(',');
            int i = 0;
    
            foreach (string s1 in rawformula)
            {
                TagField1.Add(new Tag() { Text = s1, Value = i++.ToString() });
            }        
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head id="Head1" runat="server">
        <title>TagField</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
    
            <ext:TagField ID="TagField1" runat="server" Width="500" TypeAhead="true">
            </ext:TagField>
    
            <ext:Button runat="server" Text="OK">
                <Listeners>
                    <Click Handler="App.direct.AddTags();" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
  7. #7
    Hi @Mimisss
    thanks for sample ,can you plz help ,how I add tag with javascript code.please see the post.
    http://forums.ext.net/showthread.php...l=1#post224751
  8. #8
    My answer is a workaround, which calls a DirectMethod from javascript. So, Click handler is javascript that just calls the server method, which in turn populates the tagfield.
  9. #9
    yes.but I don't want to use a Serverside method for this,thats why I want to use javascript.I think If I use
    App.tag.addItem('k', 1)
    then I can add value and text where I can set unique value for duplicate text.
    Last edited by matrixwebtech; Dec 30, 2014 at 2:42 PM.
  10. #10
    Please, use addTag (not addItem) as follows:

    App.tag.addTag({ text: '+', value: 1 });
    App.tag.addTag({ text: '+', value: 2 });
    ...
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] TagField : Remove.Handler not fire
    By matrixwebtech in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Dec 29, 2014, 3:35 PM
  2. Replies: 2
    Last Post: May 02, 2014, 1:36 PM
  3. [CLOSED] TagField Code Behind setValue
    By rsnead in forum 2.x Legacy Premium Help
    Replies: 11
    Last Post: Feb 16, 2014, 3:28 PM
  4. Store not working with TagField
    By GKG4 in forum 2.x Help
    Replies: 5
    Last Post: Feb 13, 2014, 5:20 AM
  5. [CLOSED] Simple Tagfield from Codebehind.
    By waxby in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 06, 2014, 2:51 PM

Posting Permissions