Item is not removed from hidden field

Dan's Avatar

Dan

15 May, 2013 02:43 AM

First of all, thank you for this plugin.

I wanted to submit a bug report that maybe others have run into. I am using version 1.4.

When I have a suggestion added, then click the x to delete it, the button disappears, but the hidden form field still has the value. So even if I remove the visible button the value is always submitted with my form post.

This appears to only happen with the first item added. If I have multiple items, I can delete items 2, 3, 4 etc. and they are also removed from the hidden field. Only the first item is never removed from the hidden field.

I think this has to do with the way values are removed from the hidden field. Looking at line 168 of jquery.autoSuggest.js it has this line:

values_input.val(values_input.val().replace(","+last+",",","));

This assumes that there is always a comma in front of the value. In the case of the first item added there is no preceding comma so the replacement fails. This also happens on line 334.

I'm not quite sure how to solve this myself. If you could look into this I would really appreciate it.

Thanks,
Dan

  1. 1 Posted by yogi_rrn on 24 May, 2013 01:00 PM

    yogi_rrn's Avatar

    Came across similar problem, I had modified few line in auto complete plugin.
    Here is the code I had replaced with
    This code needs to be update at two places one at “case 8 : //delete” and another in “x click event”

    var val = values_input.val().split(",")
    if (val.length === 2) {
    values_input.val(values_input.val().replace(last + ",", ""));
    }
    else if (values_input.val().indexOf(last + ",") === 0) {
    values_input.val(values_input.val().replace(last + ",", ""));
    }
    else {
    values_input.val(values_input.val().replace("," + last + ",", ","));
    }

  2. 2 Posted by The Brn on 12 Aug, 2013 07:57 AM

    The Brn's Avatar

    I have the same problem. I'm running the news Version 1.4, from Mar. 23,2010. The autoSuggest is part of an dialog box. After closing and re-opening the box, I'm still able to remove the added elements, but the values of the hidden field are unchanged/not removed.

    @ yogi_rrn The code at “case 8 : //delete” is very different from your code. So my question: do I have to add you lines or may i have to remove the existing. Here is the original code:

    case 8:  // delete
                                if(input.val() == ""){
    var last = values_input.val().split(","); last = last[last.length - 2]; selections_holder.children().not(org_li.prev()).removeClass("selected"); if(org_li.prev().hasClass("selected")){ values_input.val(values_input.val().replace(","+last+",",",")); opts.selectionRemoved.call(this, org_li.prev()); } else { opts.selectionClick.call(this, org_li.prev()); org_li.prev().addClass("selected");
    } } if(input.val().length == 1){ results_holder.hide(); prev = ""; } if($(":visible",results_holder).length > 0){ if (timeout){ clearTimeout(timeout); } timeout = setTimeout(function(){ keyChange(); }, opts.keyDelay); } break;

    2nd: i can't find the “x click event”, you are talking about...

  3. 3 Posted by yogi_rrn on 12 Aug, 2013 11:28 AM

    yogi_rrn's Avatar

    Referring to our code line
    “values_input.val(values_input.val().replace(","+last+",",","));"

    Replace / Update with code with :

    var val = values_input.val().split(",")
    if (val.length === 2) {
    values_input.val(values_input.val().replace(last + ",", "")); } else if (values_input.val().indexOf(last + ",") === 0) { values_input.val(values_input.val().replace(last + ",", ""));
    } else {
    values_input.val(values_input.val().replace("," + last + ",", ",")); }

    For “x click event” refer function add_selected_item(data, num) {

    Replace this line "values_input.val(values_input.val().replace("," + data[opts.selectedValuesProp] + ",", ","));"

    with :

    var val = values_input.val().split(",")
    if (val.length === 2) {
    values_input.val(values_input.val().replace(data[opts.selectedValuesProp] + ",", "")); } else if (values_input.val().indexOf(data[opts.selectedValuesProp] + ",") === 0) {
    values_input.val(values_input.val().replace(data[opts.selectedValuesProp] + ",", "")); } else {
    values_input.val(values_input.val().replace("," + data[opts.selectedValuesProp] + ",", ",")); }

  4. 4 Posted by The Brn on 14 Aug, 2013 08:43 AM

    The Brn's Avatar

    @yogi_rrn
    Works great, thank you.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac