From ef72b23a50e0edb0ea7aa69442e321ebcecd1a8d Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 20:16:00 +0100 Subject: [PATCH] Pull out of input bind --- Views/FormView.js | 64 +---------------------------------------------- 1 file changed, 1 insertion(+), 63 deletions(-) diff --git a/Views/FormView.js b/Views/FormView.js index 8453e8e..b77f813 100644 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -78,7 +78,7 @@ for(i = 0; i < length; i++) { switch(elements[i].tagName) { case 'input': - this.bindInput(elements[i]); + jsOMS.UI.Input.bind(elements[i]) break; case 'select': this.bindSelect(elements[i]); @@ -103,66 +103,4 @@ this.unbind(); 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 || {}));