From 2aec4430b8cf957da407efd990a7bcb9c57ec909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Sat, 27 May 2017 13:44:30 -0300 Subject: [PATCH 1/2] added handler for select item, custom id and label field --- .gitignore | 1 + dist/jquery.bootcomplete.js | 12 ++++++++++-- nbproject/project.properties | 3 +++ nbproject/project.xml | 9 +++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..14bc68c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/nbproject/private/ \ No newline at end of file diff --git a/dist/jquery.bootcomplete.js b/dist/jquery.bootcomplete.js index 25e6c10..b5f435c 100644 --- a/dist/jquery.bootcomplete.js +++ b/dist/jquery.bootcomplete.js @@ -18,8 +18,11 @@ idField : true, idFieldName : $(this).attr('name')+"_id", minLength : 3, + id: 'id', + label: 'label', dataParams : {}, - formParams : {} + formParams : {}, + select: function(item) {} } var settings = $.extend( {}, defaults, options ); @@ -77,7 +80,7 @@ success: function( json ) { var results = '' $.each( json, function(i, j) { - results += ''+j.label+'' + results += ''+j[settings.label]+'' }); $(that).next('.'+settings.menuClass).html(results) @@ -104,6 +107,11 @@ //ensure we trigger the onchange so we can do stuff $(that).prev('input[name="' + settings.idFieldName + '"]').trigger('change'); } + } else { + var item = {}; + item.id = $(this).data('id'); + item.label= $(this).data('label'); + settings.select(item); } $(that).next('.' + settings.menuClass).hide(); return false; diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..da97eba --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,3 @@ +files.encoding=UTF-8 +site.root.folder= +source.folder= diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..6812457 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.web.clientproject + + + bootcomplete.js + + + From d4c55d67df0bfa6a207a3ba9003f3170beba669c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Sat, 8 Jul 2017 20:40:08 -0300 Subject: [PATCH 2/2] added handler for empty result --- dist/jquery.bootcomplete.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dist/jquery.bootcomplete.js b/dist/jquery.bootcomplete.js index b5f435c..9903357 100644 --- a/dist/jquery.bootcomplete.js +++ b/dist/jquery.bootcomplete.js @@ -86,6 +86,10 @@ $(that).next('.'+settings.menuClass).html(results) $(that).next('.'+settings.menuClass).children().on("click", selectResult) $(that).next('.'+settings.menuClass).show() + + if(json.length == 0) { + settings.handleEmpty(); + } } }) @@ -120,4 +124,4 @@ return this; }; -}( jQuery )); +}( jQuery )); \ No newline at end of file