views:

129

answers:

0

I have strange problem with jquery autocomplete in my asp.net mvc (C#) application.

I was trying to clear the text and save empty string to my database, but it doesn't clears and i am getting the old value in the form collection. The text seems to be cleared on seeing the browser, but when i saw it through the firebug, the value still exists. This happens in firefox and chrome only and not in IE.

Following is the autocomplete code:

$("#GiftPartNumber2").autocomplete('<%=Url.Action("Gifts", "Product") %>', {
        dataType: 'json',
        max: 50, width: 300, mustMatch: true,
        parse: function(data) {
            var rows = new Array();
            for (var i = 0; i < data.length; i++) {
                rows[i] = { data: data[i], value: data[i].PartNumber + "[" + data[i].ProductName + "]", result: data[i].PartNumber };
            }
            return rows;
        },
        formatItem: function(row) {
            if (row.PartNumber != "") {
                return row.PartNumber + "[" + row.ProductName + "]";
            }
        },
        formatResult: function(row) {
            return row.PartNumber;
        },
        change: function(event, ui) {
            if (options.mustMatch) {
                var found = $('.ui-autocomplete li').text().search($(this).val());

                if (found < 0) {
                    $(this).addClass('ui-autocomplete-nomatch').val('');
                    $(this).Watermark('Part No');
                    $('#GiftProductId2').val('0');
                    $(this).delay(1500).removeClass('ui-autocomplete-nomatch', 500);
                }
            }
        }
    }).result(function(e, row) {
        if (row) {
            $('#GiftProductId2').val(row.ProductId);
        }
        else {
            $('#GiftProductId2').val('0');
        }
    });

Whats wrong with this?

Here is the screen shot attached, alt text