From eaa27696f1634cdbe0c75a13d331f3071adb1fb9 Mon Sep 17 00:00:00 2001 From: kinguru Date: Sat, 20 Aug 2016 10:17:17 +0300 Subject: [PATCH] Behavior to not override existing FieldId Added logic to work properly with existing input hidden FieldId. To not override it. --- dist/jquery.bootcomplete.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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;