mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-02-09 06:08:40 +00:00
Pull out of input bind
This commit is contained in:
parent
91d8de12a5
commit
ef72b23a50
|
|
@ -78,7 +78,7 @@
|
||||||
for(i = 0; i < length; i++) {
|
for(i = 0; i < length; i++) {
|
||||||
switch(elements[i].tagName) {
|
switch(elements[i].tagName) {
|
||||||
case 'input':
|
case 'input':
|
||||||
this.bindInput(elements[i]);
|
jsOMS.UI.Input.bind(elements[i])
|
||||||
break;
|
break;
|
||||||
case 'select':
|
case 'select':
|
||||||
this.bindSelect(elements[i]);
|
this.bindSelect(elements[i]);
|
||||||
|
|
@ -103,66 +103,4 @@
|
||||||
this.unbind();
|
this.unbind();
|
||||||
this.initializeMembers();
|
this.initializeMembers();
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.FormView.prototype.bindInput = function(input)
|
|
||||||
{
|
|
||||||
let listId, list,
|
|
||||||
self = this;
|
|
||||||
|
|
||||||
if((listId = input.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') {
|
|
||||||
input.addEventListener('change', function(event) {
|
|
||||||
self.addRemoteDatalistOptions(input, list);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
jsOMS.FormView.prototype.addRemoteDatalistOptions = function(input, datalist)
|
|
||||||
{
|
|
||||||
this.clearDatalistOptions(datalist);
|
|
||||||
|
|
||||||
let request = new Request();
|
|
||||||
request.setData(input.value);
|
|
||||||
request.setType('json');
|
|
||||||
request.setUri(datalist.getAttribute('data-list-src'));
|
|
||||||
request.setMethod(jsOMS.EnumRequestMethod.POST);
|
|
||||||
request.setRequestHeader('Content-Type', 'application/json');
|
|
||||||
request.setSuccess(function (xhr) {
|
|
||||||
try {
|
|
||||||
let o = JSON.parse(xhr.response),
|
|
||||||
response = new Response(o),
|
|
||||||
responseLength = response.count(),
|
|
||||||
tempResponse = null,
|
|
||||||
success = null;
|
|
||||||
|
|
||||||
for (let k = 0; k < responseLength; k++) {
|
|
||||||
tempResponse = response.get(k);
|
|
||||||
console.log(tempResponse);
|
|
||||||
|
|
||||||
let option = null,
|
|
||||||
data = tempResponse.getData(),
|
|
||||||
length = data.length;
|
|
||||||
|
|
||||||
for(let i = 0; i < length; i++) {
|
|
||||||
option = document.createElement('option');
|
|
||||||
datalist.appendChild(option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (exception) {
|
|
||||||
self.app.logger.error('Invalid JSON object: ' + xhr, 'FormManager')
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
request.send();
|
|
||||||
};
|
|
||||||
|
|
||||||
jsOMS.FormView.prototype.clearDatalistOptions = function(datalist)
|
|
||||||
{
|
|
||||||
let length = datalist.options.length,
|
|
||||||
i = 0;
|
|
||||||
|
|
||||||
for(i = 0; i < length; i++) {
|
|
||||||
datalist.remove(0);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}(window.jsOMS = window.jsOMS || {}));
|
}(window.jsOMS = window.jsOMS || {}));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user