From 09bc37b59e306c4f2f4f3b1ac12baaf5f6589b33 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 7 May 2019 20:02:10 +0200 Subject: [PATCH] Implement cancel button in input field --- UI/Component/Input.js | 53 +++++++------------------------------------ UI/GeneralUI.js | 2 +- 2 files changed, 9 insertions(+), 46 deletions(-) diff --git a/UI/Component/Input.js b/UI/Component/Input.js index 4286701..eb39fef 100644 --- a/UI/Component/Input.js +++ b/UI/Component/Input.js @@ -47,54 +47,17 @@ export class Input { static bindElement(input) { if (typeof input === 'undefined') { - throw 'Input element required' + throw 'Input element required'; } - const self = this; + const type = input.type; - input.addEventListener('change', function changeBind(event) - { - console.log('ttttttt'); - /* Handle remote datalist/autocomplete input element */ - let listId, list; - if (typeof (listId = this.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') { - self.addRemoteDatalistOptions(this, list); - } - - /* Handle html defined functions */ - let change; - if (typeof (change = this.getAttribute('data-change-func')) !== 'undefined') { - change(this); - } - - /* Handle pre-defined dynamic change events */ - let ref; - if (typeof (ref = this.getAttribute('data-ref')) !== 'undefined') { - let e = document.getElementById(ref); - - if (!e) { - return; - } - - switch (e.tagName) { - case 'ul': - break; - case 'table': - break; - default: - } - } - }); - - let dataButton; - if (typeof (dataButton = input.getAttribute('data-button')) !== 'undefined') { - this.app.inputManager.getKeyboardManager().bind(input, 13, function () - { - const db = document.getElementById(dataButton); - - if (db) { - db.click(); - } + const removeContentButton = input.parentNode.querySelector('.fa-times'); + if (removeContentButton !== null + && type !== 'submit' && type !== 'button') { + removeContentButton.addEventListener('click', function() { + input.value = ''; + input.focus(); }); } }; diff --git a/UI/GeneralUI.js b/UI/GeneralUI.js index af0e6ae..fd1e1b0 100644 --- a/UI/GeneralUI.js +++ b/UI/GeneralUI.js @@ -1,6 +1,6 @@ -import { AdvancedInput } from './Component/AdvancedInput.js'; import { UriFactory } from '../Uri/UriFactory.js'; +import { AdvancedInput } from './Component/AdvancedInput.js'; /** * UI manager for handling basic ui elements.