updates
This commit is contained in:
@@ -3,67 +3,69 @@ import { El } from "../../utils/dom";
|
|||||||
|
|
||||||
export class Cancelable {
|
export class Cancelable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancelable, Construct
|
* Cancelable, Construct
|
||||||
*/
|
*/
|
||||||
constructor(target, events) {
|
constructor(target, events) {
|
||||||
|
|
||||||
let that = this;
|
this.target = target;
|
||||||
|
this.events = events || {};
|
||||||
|
|
||||||
this.target = target;
|
if (target.dxData('cancelable')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
events = events || {};
|
target.dxData('cancelable', this);
|
||||||
|
|
||||||
target.dxData('cancelable', this);
|
this.iconHandler = El('i', { className: 'icon-right icon-clear hide' });
|
||||||
|
|
||||||
this.iconHandler = El('i', { className: 'icon-right icon-clear hide' });
|
let elType = target.tagName.toLowerCase();
|
||||||
|
|
||||||
let elType = target.tagName.toLowerCase();
|
if (elType == 'select' || (elType == 'input' && target.type == 'text')) {
|
||||||
|
|
||||||
|
const val = this.target.dxVal();
|
||||||
|
|
||||||
if (elType == 'select' || (elType == 'input' && target.type == 'text')) {
|
this.emptyVal = '';
|
||||||
|
|
||||||
let val = this.target.dxVal();
|
|
||||||
|
|
||||||
let emptyVal = '';
|
if (elType == 'select' && target.dxFind('option[value="0"]')) {
|
||||||
|
this.emptyVal = '0';
|
||||||
|
}
|
||||||
|
|
||||||
if (elType == 'select' && target.dxFind('option[value="0"]')) {
|
this.iconHandler.classList.toggle('hide', val == this.emptyVal);
|
||||||
emptyVal = '0';
|
|
||||||
}
|
target.after(this.iconHandler);
|
||||||
|
|
||||||
this.iconHandler.classList.toggle('hide', val == emptyVal);
|
target.dxOn(elType == 'input' ? 'input.cancelable changed.cancelable' : 'change.cancelable', (_, t) => this.iconHandler.classList.toggle('hide', t.dxVal() == this.emptyVal));
|
||||||
|
|
||||||
target.after(this.iconHandler);
|
|
||||||
|
|
||||||
target.dxOn(elType == 'input' ? 'input.cancelable changed.cancelable' : 'change.cancelable', function() {
|
this.iconHandler.dxOn('click', _ => this.clear());
|
||||||
that.iconHandler.classList.toggle('hide', this.dxVal() == emptyVal);
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
this.iconHandler.dxOn('click', function() {
|
/**
|
||||||
|
* Cancelble, Clear Value
|
||||||
|
*/
|
||||||
|
clear() {
|
||||||
|
|
||||||
target.dxVal(emptyVal);
|
this.target.value = this.emptyVal;
|
||||||
|
|
||||||
if ('value' in that.target.dataset) {
|
if ('value' in this.target.dataset) {
|
||||||
that.target.dataset.value = '';
|
this.target.dataset.value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
that.iconHandler.classList.add('hide');
|
this.iconHandler.classList.add('hide');
|
||||||
|
|
||||||
that.target.dxTrigger('clear');
|
this.target.dxTrigger('clear');
|
||||||
Ut.trigger(events.onClear, that);
|
Ut.trigger(this.events.onClear, this);
|
||||||
});
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancelble, Destroy
|
* Cancelble, Destroy
|
||||||
*/
|
*/
|
||||||
destroy() {
|
destroy() {
|
||||||
|
|
||||||
this.target.dxOff('input.cancelable change.cancelable');
|
this.target.dxOff('input.cancelable change.cancelable');
|
||||||
this.target.dxRemoveData('cancelable');
|
this.target.dxRemoveData('cancelable');
|
||||||
|
|
||||||
this.iconHandler.remove();
|
this.iconHandler.remove();
|
||||||
|
}
|
||||||
return this.target;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user