Results 1 to 5 of 5

Thread: working with Tags (Keywords)

  1. #1

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    489

    Resolved working with Tags (Keywords)

    hi
    i am working on a website wherein the user can save tags (Keywords) multiple tags separated by comma, against a product which can later be used for search. the user can have a max. of 50 tags per products. (This is similar to the tags we have here below the post)

    i have searched a lot and found many eg. which are working in html but when i try to implement it in ASP it is not working.

    i also would appreciate someone guide me as to how is the best to save it.
    i am planning to save the comma separated tags in a single filed, i am also puzzled as to how i will display them back.

    should i save it in as a single record or save each tags as a separate records

    pls. help me out.
    thanks in advance.
    Last edited by kuldevbhasin; Sep 10th, 2024 at 09:24 AM.
    The only time you run out of chances is when you stop taking them.
    The mind is like a parachute.
    It doesn’t work unless it’s open.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,686

    Re: working with Tags (Keywords)

    Quote Originally Posted by kuldevbhasin View Post
    when i try to implement it in ASP it is not working.
    If it didn't work then you did it wrong. If we can't see what you did, we can't see what's wrong with it. Don't ask us to explain an entire process when you may already know 99% of it. Show us what you did, explain what you expect it to do and explain what actually happens when you use it.
    Quote Originally Posted by kuldevbhasin View Post
    should i save it in as a single record or save each tags as a separate records
    How to best store them depends on how you intend to use them. If you want to find records associated with an individual tag then a single, comma-separated value would be a bad idea because you couldn't use an index to accelerate database searches.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    489

    Re: working with Tags (Keywords)

    sorry my bad. i should have put what i am working with.
    i got it working. posting it here just in case it may help someone.

    HTML
    Code:
       <asp:TextBox ID="txttags" runat="server" class="form-control" data-role="tagsinput"
           Font-Size="Large"></asp:TextBox>
    CSS
    Code:
    .bootstrap-tagsinput {
      border: 1px solid #ccc;
      display: inline-block;
      padding: 4px 6px;
      margin-bottom: 10px;
      color: #555;
      vertical-align: middle;
      border-radius: 4px;
      max-width: 100%;
      line-height: 22px;
      cursor: text;
    }
    .bootstrap-tagsinput input {
      border: double;
      box-shadow: none;
      outline: none;
      background-color: transparent;
      padding: 0;
      margin: 0;
      width: auto !important;
      max-width: inherit;
    }
    .bootstrap-tagsinput input:focus {
      border: none;
      box-shadow: none;
    }
    .bootstrap-tagsinput .tag {
      margin-right: 2px;
      color: white;
    }
    .bootstrap-tagsinput .tag [data-role="remove"] {
      margin-left: 8px;
      cursor: pointer;
    }
    .bootstrap-tagsinput .tag [data-role="remove"]:after {
      content: "x";
      padding: 0px 2px;
    }
    .bootstrap-tagsinput .tag [data-role="remove"]:hover {
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
    }
    .bootstrap-tagsinput .tag [data-role="remove"]:hover:active {
      box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
    }
    JS
    Code:
    const ul = document.querySelector("ul"),
    input = document.querySelector("input"),
    tagNumb = document.querySelector(".details span");
    
    let maxTags = 10,
    tags = ["coding", "nepal"];
    
    countTags();
    createTag();
    
    function countTags(){
        input.focus();
        tagNumb.innerText = maxTags - tags.length;
    }
    
    function createTag(){
        ul.querySelectorAll("li").forEach(li => li.remove());
        tags.slice().reverse().forEach(tag =>{
            let liTag = `<li>${tag} <i class="uit uit-multiply" onclick="remove(this, '${tag}')"></i></li>`;
            ul.insertAdjacentHTML("afterbegin", liTag);
        });
        countTags();
    }
    
    function remove(element, tag){
        let index  = tags.indexOf(tag);
        tags = [...tags.slice(0, index), ...tags.slice(index + 1)];
        element.parentElement.remove();
        countTags();
    }
    
    function addTag(e){
        if(e.key == "Enter"){
            let tag = e.target.value.replace(/\s+/g, ' ');
            if(tag.length > 1 && !tags.includes(tag)){
                if(tags.length < 10){
                    tag.split(',').forEach(tag => {
                        tags.push(tag);
                        createTag();
                    });
                }
            }
            e.target.value = "";
        }
    }
    
    input.addEventListener("keyup", addTag);
    
    const removeBtn = document.querySelector(".details button");
    removeBtn.addEventListener("click", () =>{
        tags.length = 0;
        ul.querySelectorAll("li").forEach(li => li.remove());
        countTags();
    });
    thanks @jmcilhinney
    The only time you run out of chances is when you stop taking them.
    The mind is like a parachute.
    It doesn’t work unless it’s open.

  4. #4

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    489

    Re: working with Tags (Keywords)

    hi.
    i am still struggling with this. can anyone pls. help me out. pls.
    The only time you run out of chances is when you stop taking them.
    The mind is like a parachute.
    It doesn’t work unless it’s open.

  5. #5
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,897

    Re: working with Tags (Keywords)

    Quote Originally Posted by kuldevbhasin View Post
    hi.
    i am still struggling with this. can anyone pls. help me out. pls.
    I don't have the expertise to help but in post #3 you said it is working and it is an example of that and then in post #4 you are struggling. Maybe you should say with what.
    Please remember next time...elections matter!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width