diff --git a/dist/jquery.bootcomplete.js b/dist/jquery.bootcomplete.js index c29a94f..2153554 100644 --- a/dist/jquery.bootcomplete.js +++ b/dist/jquery.bootcomplete.js @@ -27,7 +27,11 @@ $(this).attr('autocomplete','off') $(this).wrap('
') if(settings.idField){ - $('').insertBefore($(this)) + // insert new hidden field if not already one present + var existingHiddenField = $('input[name="' + settings.idFieldName + '"]'); + if (!existingHiddenField || !existingHiddenField.length) { + $('').insertBefore($(this)); + } } $('').insertAfter($(this)) @@ -79,7 +83,7 @@ function selectResult(){ $(that).val($(this).data('label')) if(settings.idField){ - $(that).prev('input[name="'+settings.idFieldName+'"]').val($(this).data('id')) + $('input[name="'+settings.idFieldName+'"]').val($(this).data('id')); } $(that).next('.'+settings.menuClass).hide() return false;