JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/css/bootstrap-editable.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/js/bootstrap-editable.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://nparashuram.com/jquery-indexeddb/dist/jquery.indexeddb.js"></script>
<a id="TypeID" data-type="select" data-pk="1966_TypeID" data-original-title="Please Select" data-pid="36" class="editable editable-click">3609</a>
CSS
body {
padding: 300px;
}
.editable-click {
cursor: pointer;
}
JavaScript
//uncomment this function call in order to add test data to local storage
//deleteDatabase();
makeEditable();
function popSelectBox(PID) {
var rtn = [];
$.indexedDB('testDatabase').objectStore('Lookup').index('PID').each(function (i) {
var source = {};
source.value = i.value.ID;
source.text = i.value.Name;
rtn.push(source);
}, PID).done(function (r, e) {
console.log(rtn);
console.log('popSelectBox function (I expect to see this first) - This section should complete before the makeEditable function');
return rtn;
});
}
//makeEditable function adds editable functionality
function makeEditable() {
$('.editable').editable({
validate: function (value) {
if ($.trim(value) === '') {
return 'This field is required';
}
return false;
},
success: function (response, newValue) {
console.log($(this).data('pk'), newValue);
//$(this).parent().css('background-color', 'green');
},
/**** this is the problem section of this function ****/
source: function () {
//if the type is a select list then we need to populate it, this is done here
if ($(this).data('type') === 'select') {
var d = $.Deferred();
$.when(d).done(function (v) {
console.log(v);
return v;
});
d.resolve(popSelectBox($(this).data('pid').toString()));
console.log('makeEditable function (I expect to see this last) - This section should wait for the popSelectBox function to finish');
}
}
});
}
/*** local storage setup ***/
function createDatabase() {
var dbOpenPromise = $.indexedDB("testDatabase", {
// The second parameter is optional
"version": 3, // Integer version that the DB should be opened with
"upgrade": function...