Skip to content

Commit

Permalink
Merge pull request #34 from komcal/custom-result-display
Browse files Browse the repository at this point in the history
Custom result display
  • Loading branch information
earthchie authored Oct 17, 2018
2 parents 7b594d9 + de681c5 commit 138e47d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,19 @@ $.Thailand({
// (ไม่ระบุก็ได้หากไม่จำเป็นต้องใช้)
onLoad: function(){
console.info('Autocomplete is ready!');
},

// object templates ใช้สำหรับ render dataset ใน typeahead.js
// สามารถอ่านเพิ่มเติมได้ที่ field templates ใน https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#datasets
// (ไม่ระบุก็ได้หากไม่จำเป็นต้องใช้)
templates: {
empty: ' ',
suggestion: function (data) {
if (data.zipcode) {
data.zipcode = ' » ' + data.zipcode;
}
return '<div>' + data.district + ' » ' + data.amphoe + ' » ' + data.province + data.zipcode + '</div>';
}
}
});
```
Expand Down
5 changes: 3 additions & 2 deletions jquery.Thailand.js/src/jquery.Thailand.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ $.Thailand = function (options) {
$.Thailand.DB = DB;
var i,
key,
templates = { // template of autocomplete choices
defaultTemplates = { // template of autocomplete choices
empty: ' ',
suggestion: function (data) {
if (data.zipcode) {
Expand All @@ -222,6 +222,7 @@ $.Thailand = function (options) {
}

};
var templates = typeof options.templates === 'object' ? Object.assign(defaultTemplates, options.templates) : defaultTemplates

for (i in options) {
if (i.indexOf('$') > -1 && i !== '$search' && options.hasOwnProperty(i) && options[i]) {
Expand Down Expand Up @@ -329,7 +330,7 @@ $.Thailand.defaults = {

onLoad: function () {},
onDataFill: function () {},

templates: false,
$district: false,
$district_code: false, // geodb only
$amphoe: false,
Expand Down

0 comments on commit 138e47d

Please sign in to comment.