UNPKG

cipherguard-mad

Version:

Cipherguard javascript application library for the open source password manager for teams

68 lines (58 loc) 1.93 kB
/** * Cipherguard ~ Open source password manager for teams * Copyright (c) KhulnaSoft Ltd (https://www.khulnasoft.com) * * Licensed under GNU Affero General Public License version 3 of the or any later version. * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) KhulnaSoft Ltd (https://www.khulnasoft.com) * @license https://opensource.org/licenses/AGPL-3.0 AGPL License * @link https://www.khulnasoft.com KhulnaSoft(tm) */ import $ from 'jquery'; import domEvents from 'can-dom-events'; import FormElementView from '../element'; /** * @inherits mad.view.form.Element */ const Textbox = FormElementView.extend('mad.view.form.Textbox', /* @static */ { }, /** @prototype */ { /** * Store here the last reference of a setTimeout call. * see: changed event handler. */ _changeTimeout: null, /** * Get the value from the associated HTML Element. * @return {mixed} The value of the component */ getValue: function() { return $(this.element).val(); }, /** * Set the value of the associated HTML Element. * @param {mixed} value The value to set */ setValue: function(value) { $(this.element).val(value); }, /** * The value of the HTML Element changed. */ '{element} input': function() { const newValue = this.getValue(); if (newValue.length >= this.getController().options.onChangeAfterLength) { // If a trigger of changed event is already schedule, remove it. if (this._changeTimeout != null) { clearTimeout(this._changeTimeout); } this._changeTimeout = setTimeout(() => { domEvents.dispatch(this.element, {type: 'changed', data: { value: this.getValue() }}); }, this.getController().options.onChangeTimeout); } } }); export default Textbox;