javascriptjqueryasp.netjquery-tags-input

Jquery Tags-input add tags to asp:textbox from prompting with percent sign value Uncaught Error: Syntax error, unrecognized expression: %


I have a prompting to add text to asp:textbox with percent-sign from Javascript and try to escaped % to string

<asp:TextBox ID="txtValue" Enabled="true" CssClass="form-control" TextMode="MultiLine" Rows="5" runat="server"></asp:TextBox>


     sql = prompt("Enter Condition");
                if (sql != null) {
                    var sqlcode = cond.concat(" like ", " \'\%]", sql, "\%\' ");
                    $('#<%= txtValue.ClientID %>').addTag(sqlcode);
                }

but this still shown me

Uncaught Error: Syntax error, unrecognized expression: %test%

jquery-tags-input initialize

   <script>
        function onAddTag(tag) {
            alert("Added a tag: " + tag);
        }

        function onRemoveTag(tag) {
            alert("Removed a tag: " + tag);
        }

        function onChangeTag(input, tag) {
            alert("Changed a tag: " + tag);
        }

        $(document).ready(function () {
             $('#<%= txtSQL.ClientID %>').tagsInput({
              width: 'auto',
              'delimiter': ['  '],
              defaultText: "",
unique:false,

              onAddTag: function (elem, elem_tags) {
                  var languages = ['or', 'and'];
                  $('.tag', elem_tags).each(function () {
                      if ($(this).text().search(new RegExp('\\b(' + languages.join('|') + ')\\b')) >= 0)
                          $(this).css('background-color', 'blue');
                  });
              },
              onChange: function (elem, elem_tags) {
                  var languages = ['or', 'and'];
                  $('.tag', elem_tags).each(function () {
                      if ($(this).text().search(new RegExp('\\b(' + languages.join('|') + ')\\b')) >= 0)
                          $(this).css('background-color', 'blue');
                  });
              }


          });

  });
</script>

this happened with ' Singlequote too

how can I escaped them to String, I try to use double backslash \\ but it's just use for metacharacters on input ID I can't use with value.


Solution

  • I solved my solutions by delete these proc

    onAddTag: function (elem, elem_tags) {
        var languages = ['or', 'and'];
        $('.tag', elem_tags).each(function () {
            if ($(this).text().search(new RegExp('\\b(' + languages.join('|') + ')\\b')) >= 0)
                $(this).css('background-color', 'blue');
        });
    },
    onChange: function (elem, elem_tags) {
         var languages = ['or', 'and'];
         $('.tag', elem_tags).each(function () {
            if ($(this).text().search(new RegExp('\\b(' + languages.join('|') + ')\\b')) >= 0)
               $(this).css('background-color', 'blue');
         });
    }
    

    Then it worked like a charm :)