Skip to content

Commit

Permalink
hopefully more stable now
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodlopes committed Jul 7, 2017
1 parent 527a6e5 commit 2b17791
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-flexdatalist",
"version": "2.0.6",
"version": "2.0.7",
"main": ["jquery.flexdatalist.js"],
"dependencies": {
"jquery": ">=1.8"
Expand Down
27 changes: 14 additions & 13 deletions jquery.flexdatalist.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Autocomplete input fields, with support for datalists.
*
* Version:
* 2.0.7 RC
* 2.0.7
*
* Depends:
* jquery.js > 1.8.3
Expand Down Expand Up @@ -421,12 +421,10 @@ jQuery.fn.flexdatalist = function (_option, _value) {
_normalize: function (data, callback) {
var options = _this.options.get();
data = this.toObj(data);
if (typeof options.valueProperty === 'string' && (this.isCSV() || this.isMixed())) {
if (typeof options.valueProperty === 'string' && !this.isJSON(data)) {
var _searchIn = options.searchIn,
_searchEqual = options.searchEqual;
if (typeof options.valueProperty === 'string') {
options.searchIn = options.valueProperty.split(',');
}
options.searchIn = options.valueProperty.split(',');
options.searchEqual = true;
_this.search.get(data, function (matches) {
callback(matches);
Expand Down Expand Up @@ -747,9 +745,7 @@ jQuery.fn.flexdatalist = function (_option, _value) {
val = $.map(val, function (v) {
return $.trim(v);
});
} else if (this.isJSON()) {
val = JSON.parse(val);
} else if (this.isMixed() && (val.indexOf('{') === 0 || val.indexOf('[{') === 0)) {
} else if (this.isJSON() || (this.isMixed() && this.isJSON(val))) {
val = JSON.parse(val);
}
}
Expand All @@ -771,9 +767,14 @@ jQuery.fn.flexdatalist = function (_option, _value) {
return $.trim(val);
},
/**
* Is value expected to be JSON (either object or string).
* If argument is passed, will check if is a valid JSON object/string.
* otherwise will check if JSON is the value expected for input
*/
isJSON: function () {
isJSON: function (str) {
if (typeof str !== 'undefined') {
str = _this.isObject(str) ? JSON.stringify(str) : str;
return (str.indexOf('{') === 0 || str.indexOf('[{') === 0);
}
var options = _this.options.get(),
prop = options.valueProperty;
return (options.selectionRequired && (_this.isObject(prop) || prop === '*'));
Expand Down Expand Up @@ -1384,7 +1385,7 @@ jQuery.fn.flexdatalist = function (_option, _value) {
*/
write: function (key, value, lifetime, global) {
if (_this.cache.isSupported()) {
key = this.keyGen(key, global);
key = this.keyGen(key, undefined, global);
var object = {
value: value,
// Get current UNIX timestamp
Expand All @@ -1402,7 +1403,7 @@ jQuery.fn.flexdatalist = function (_option, _value) {
*/
read: function (key, global) {
if (_this.cache.isSupported()) {
key = this.keyGen(key, global);
key = this.keyGen(key, undefined, global);
var data = localStorage.getItem(key);
if (data) {
var object = JSON.parse(data);
Expand All @@ -1426,7 +1427,7 @@ jQuery.fn.flexdatalist = function (_option, _value) {
*/
delete: function (key, global) {
if (_this.cache.isSupported()) {
key = this.keyGen(key, global);
key = this.keyGen(key, undefined, global);
localStorage.removeItem(key);
}
},
Expand Down
Loading

0 comments on commit 2b17791

Please sign in to comment.