From 0119240944459081fc2a2e00fb6c78cab9e37af0 Mon Sep 17 00:00:00 2001 From: anibalmf1 Date: Wed, 15 Jul 2015 13:20:59 -0300 Subject: [PATCH] Update search.js to allow custom display fields This change allow the developter to choose the field to display in the results. So we don't have to change our json's object field names to the fixed ones (title, price and description). usage: $('div[name="searchDiv"]').search({ source: [{id:0, myfield: 'some text', extrafield: 'ST'}, {id:1, myfield: 'another text', extrafield: 'AT'}], searchFields: [ myfield ], displayField: extrafield }); --- src/definitions/modules/search.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/definitions/modules/search.js b/src/definitions/modules/search.js index 6cf94f122..b1bc3cf0e 100644 --- a/src/definitions/modules/search.js +++ b/src/definitions/modules/search.js @@ -824,7 +824,7 @@ $.fn.search = function(parameters) { } } if($.isFunction(template)) { - html = template(response); + html = template(response, settings); } else { module.error(error.noTemplate, false); @@ -1048,6 +1048,9 @@ $.fn.search.settings = { 'description' ], // fields to search + + displayField : '', + // field to display in standard results template searchFullText : true, // whether to include fuzzy results in local search @@ -1225,7 +1228,7 @@ $.fn.search.settings = { } return false; }, - standard: function(response) { + standard: function(response, settings) { var html = '' ; @@ -1247,6 +1250,9 @@ $.fn.search.settings = { ; } html += '
'; + if (settings.displayField.length > 0){ + html += '
' + result[settings.displayField] + '
'; + } if(result.price !== undefined) { html += '
' + result.price + '
'; }