Добавлена возможность оставить пустое поле даты
This commit is contained in:
1 parent
9eb6cfb1ec
commit
8fe52a2a19
5 files changed
+20
-12
No files matched your search
+6
-3
@@ -856,7 +856,10 @@ class SmartDateField
|
||||
|
||||
this._field.addEventListener('blur', function () {
|
||||
_this.correctValue(true);
|
||||
_this.returnLastCorrectValue();
|
||||
|
||||
if (!_this._isEmptyValue(_this._field.value)) {
|
||||
_this.returnLastCorrectValue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -898,7 +901,7 @@ class SmartDateField
|
||||
return;
|
||||
}
|
||||
|
||||
this._setValueToFieled(parsedValue);
|
||||
this._setValueToField(parsedValue);
|
||||
}
|
||||
|
||||
setValue(value)
|
||||
@@ -931,7 +934,7 @@ class SmartDateField
|
||||
return this._formatter.getCorrectedValue();
|
||||
}
|
||||
|
||||
_setValueToFieled(newValue)
|
||||
_setValueToField(newValue)
|
||||
{
|
||||
let position = this._field.selectionStart;
|
||||
let isAtEnd = (position === this._field.value.length);
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
class AbstractSmartDatePart{constructor(a,b){this._state=AbstractSmartDatePart.STATE_NONE,this._cleanedValue="",this._parsedValue="",this._scanned="",this._placeholder=a,this._static=b}state(){return this._state}isNoState(){return this._state===AbstractSmartDatePart.STATE_NONE}isIncomplete(){return this._state===AbstractSmartDatePart.STATE_INCOMPLETE}isComplete(){return this._state===AbstractSmartDatePart.STATE_COMPLETE}resetState(){this._state=AbstractSmartDatePart.STATE_NONE}cleanedValue(){return this._cleanedValue}parsedValue(){return this._parsedValue}placeHolder(){return this._placeholder}isStatic(){return this._static}_isNumericSymbol(a){return"0"<=a&&"9">=a}check(a){return!1}}AbstractSmartDatePart.STATE_NONE=0,AbstractSmartDatePart.STATE_INCOMPLETE=1,AbstractSmartDatePart.STATE_COMPLETE=2;class SmartDateStaticPart extends AbstractSmartDatePart{constructor(a){super(a,!0),this._cleanedValue=a}parse(a){let b=a.value(),c=a.valueIndex();for(;c<b.length&&!this._isNumericSymbol(b[c]);)c++;return this._parsedValue=b.substring(a.valueIndex(),c),this._state=AbstractSmartDatePart.STATE_COMPLETE,a.setValueIndex(c),!0}}class AbstractSmartDateNumericPart extends AbstractSmartDatePart{constructor(a,b){super(a,!1),this._numericValue=0,this._size=b}numericValue(){return this._numericValue}formatDate(a){return""}formatValue(a){let b=this._correctValue(a)+"";return"0"==b?b:b.length>this._size?b.substring(0,this._size):b.length<this._size?b.padStart(this._size,"0"):b}_correctValue(a){return Math.round(a)}scanStringNumber(a){let b=a.valueIndex(),c=a.value();for(;b<c.length&&this._isNumericSymbol(c[b]);)b++;let d=c.substring(a.valueIndex(),b);return a.setValueIndex(b),d}calculateNumericValue(a,b){for(var c=0,d=0,e=0;c<a.length&&0===a[c];)c++;for(d=c;d<a.length&&e<b;)e=10*e+ +a[d],d++;return e>b&&d--,+a.substring(c,d)}scanValue(a,b){let c=a.valueIndex(),d=a.value(),e=0;for(;c<d.length&&this._isNumericSymbol(d[c])&&e<b;)e=10*e+ +d[c],c++;e>b&&c--;let f=d.substring(a.valueIndex(),c);return a.setValueIndex(c),f}_defineParsingState(a,b){return 0<this._numericValue&&(this._parsedValue.length>=this._size||!b)?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):10*this._numericValue>a?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}_defineCleanValue(){return this._cleanedValue="",this.isNoState()?void 0:this.isComplete()?void(this._cleanedValue=this.formatValue(this._numericValue)):void(0<this._parsedValue.length&&(this._cleanedValue=this._numericValue+""))}}class SmartDateDayPart extends AbstractSmartDateNumericPart{constructor(){super(SmartDateFormat.DAY_PLACEHOLDER,2),this.maximalValue=SmartDateDayPart.MAXIMAL_VALUE}resetState(){super.resetState(),this.maximalValue=SmartDateDayPart.MAXIMAL_VALUE}setMaximalValue(a){a!=a||a<SmartDateDayPart.MAXIMAL_VALUE_LOW_LIMIT||SmartDateDayPart.MAXIMAL_VALUE_HIGH_LIMIT<a||(this.maximalValue=a,this._numericValue<=this.maximalValue||(this._numericValue=this.maximalValue,this._defineCleanValue()))}resetMaximalValue(){this.maximalValue=SmartDateDayPart.MAXIMAL_VALUE}formatDate(a){return this.formatValue(a.getDate())}parse(a){this._parsedValue=this.scanStringNumber(a),this._numericValue=this.calculateNumericValue(this._parsedValue,this.maximalValue),this._defineParsingState(this.maximalValue,a.isOver()),this._defineCleanValue()}}SmartDateDayPart.MAXIMAL_VALUE_LOW_LIMIT=28,SmartDateDayPart.MAXIMAL_VALUE_HIGH_LIMIT=31,SmartDateDayPart.MAXIMAL_VALUE=SmartDateDayPart.MAXIMAL_VALUE_HIGH_LIMIT;class SmartDateMonthPart extends AbstractSmartDateNumericPart{constructor(){super(SmartDateFormat.MONTH_PLACEHOLDER,2)}formatDate(a){return this.formatValue(a.getMonth()+1)}parse(a){this._parsedValue=this.scanStringNumber(a),this._numericValue=this.calculateNumericValue(this._parsedValue,SmartDateMonthPart.MAXIMAL_VALUE),this._defineParsingState(SmartDateMonthPart.MAXIMAL_VALUE,a.isOver()),this._defineCleanValue()}}SmartDateMonthPart.MAXIMAL_VALUE=12;class SmartDateYearPart extends AbstractSmartDateNumericPart{constructor(){super(SmartDateFormat.YEAR_PLACEHOLDER,4)}formatDate(a){return this.formatValue(a.getFullYear())}parse(a){this._parsedValue=this.scanStringNumber(a),this._numericValue=+this._parsedValue,this._defineParsingState(),this._numericValue>SmartDateYearPart.MAXIMAL_VALUE&&(this._numericValue=SmartDateYearPart.MAXIMAL_VALUE),this.isComplete()&&this._numericValue<SmartDateYearPart.MINIMAL_VALUE&&(this._numericValue=SmartDateYearPart.MINIMAL_VALUE),this._defineCleanValue()}_defineParsingState(){return 0<this._numericValue&&this._parsedValue.length>=this._size?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}_defineCleanValue(){this._cleanedValue=0<this._numericValue?this._numericValue+"":""}}SmartDateYearPart.MINIMAL_VALUE=1e3,SmartDateYearPart.MAXIMAL_VALUE=9999;class SmartDateParseState{constructor(){this._value="",this._valueIndex=0}start(a){this._value=a,this._valueIndexLine truncated
|
||||
class AbstractSmartDatePart{constructor(a,b){this._state=AbstractSmartDatePart.STATE_NONE,this._cleanedValue="",this._parsedValue="",this._scanned="",this._placeholder=a,this._static=b}state(){return this._state}isNoState(){return this._state===AbstractSmartDatePart.STATE_NONE}isIncomplete(){return this._state===AbstractSmartDatePart.STATE_INCOMPLETE}isComplete(){return this._state===AbstractSmartDatePart.STATE_COMPLETE}resetState(){this._state=AbstractSmartDatePart.STATE_NONE}cleanedValue(){return this._cleanedValue}parsedValue(){return this._parsedValue}placeHolder(){return this._placeholder}isStatic(){return this._static}_isNumericSymbol(a){return"0"<=a&&"9">=a}check(a){return!1}}AbstractSmartDatePart.STATE_NONE=0,AbstractSmartDatePart.STATE_INCOMPLETE=1,AbstractSmartDatePart.STATE_COMPLETE=2;class SmartDateStaticPart extends AbstractSmartDatePart{constructor(a){super(a,!0),this._cleanedValue=a}parse(a){let b=a.value(),c=a.valueIndex();for(;c<b.length&&!this._isNumericSymbol(b[c]);)c++;return this._parsedValue=b.substring(a.valueIndex(),c),this._state=AbstractSmartDatePart.STATE_COMPLETE,a.setValueIndex(c),!0}}class AbstractSmartDateNumericPart extends AbstractSmartDatePart{constructor(a,b){super(a,!1),this._numericValue=0,this._size=b}numericValue(){return this._numericValue}formatDate(a){return""}formatValue(a){let b=this._correctValue(a)+"";return"0"==b?b:b.length>this._size?b.substring(0,this._size):b.length<this._size?b.padStart(this._size,"0"):b}_correctValue(a){return Math.round(a)}scanStringNumber(a){let b=a.valueIndex(),c=a.value();for(;b<c.length&&this._isNumericSymbol(c[b]);)b++;let d=c.substring(a.valueIndex(),b);return a.setValueIndex(b),d}calculateNumericValue(a,b){for(var c=0,d=0,e=0;c<a.length&&0===a[c];)c++;for(d=c;d<a.length&&e<b;)e=10*e+ +a[d],d++;return e>b&&d--,+a.substring(c,d)}scanValue(a,b){let c=a.valueIndex(),d=a.value(),e=0;for(;c<d.length&&this._isNumericSymbol(d[c])&&e<b;)e=10*e+ +d[c],c++;e>b&&c--;let f=d.substring(a.valueIndex(),c);return a.setValueIndex(c),f}_defineParsingState(a,b){return 0<this._numericValue&&(this._parsedValue.length>=this._size||!b)?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):10*this._numericValue>a?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}_defineCleanValue(){return this._cleanedValue="",this.isNoState()?void 0:this.isComplete()?void(this._cleanedValue=this.formatValue(this._numericValue)):void(0<this._parsedValue.length&&(this._cleanedValue=this._numericValue+""))}}class SmartDateDayPart extends AbstractSmartDateNumericPart{constructor(){super(SmartDateFormat.DAY_PLACEHOLDER,2),this.maximalValue=SmartDateDayPart.MAXIMAL_VALUE}resetState(){super.resetState(),this.maximalValue=SmartDateDayPart.MAXIMAL_VALUE}setMaximalValue(a){a!=a||a<SmartDateDayPart.MAXIMAL_VALUE_LOW_LIMIT||SmartDateDayPart.MAXIMAL_VALUE_HIGH_LIMIT<a||(this.maximalValue=a,this._numericValue<=this.maximalValue||(this._numericValue=this.maximalValue,this._defineCleanValue()))}resetMaximalValue(){this.maximalValue=SmartDateDayPart.MAXIMAL_VALUE}formatDate(a){return this.formatValue(a.getDate())}parse(a){this._parsedValue=this.scanStringNumber(a),this._numericValue=this.calculateNumericValue(this._parsedValue,this.maximalValue),this._defineParsingState(this.maximalValue,a.isOver()),this._defineCleanValue()}}SmartDateDayPart.MAXIMAL_VALUE_LOW_LIMIT=28,SmartDateDayPart.MAXIMAL_VALUE_HIGH_LIMIT=31,SmartDateDayPart.MAXIMAL_VALUE=SmartDateDayPart.MAXIMAL_VALUE_HIGH_LIMIT;class SmartDateMonthPart extends AbstractSmartDateNumericPart{constructor(){super(SmartDateFormat.MONTH_PLACEHOLDER,2)}formatDate(a){return this.formatValue(a.getMonth()+1)}parse(a){this._parsedValue=this.scanStringNumber(a),this._numericValue=this.calculateNumericValue(this._parsedValue,SmartDateMonthPart.MAXIMAL_VALUE),this._defineParsingState(SmartDateMonthPart.MAXIMAL_VALUE,a.isOver()),this._defineCleanValue()}}SmartDateMonthPart.MAXIMAL_VALUE=12;class SmartDateYearPart extends AbstractSmartDateNumericPart{constructor(){super(SmartDateFormat.YEAR_PLACEHOLDER,4)}formatDate(a){return this.formatValue(a.getFullYear())}parse(a){this._parsedValue=this.scanStringNumber(a),this._numericValue=+this._parsedValue,this._defineParsingState(),this._numericValue>SmartDateYearPart.MAXIMAL_VALUE&&(this._numericValue=SmartDateYearPart.MAXIMAL_VALUE),this.isComplete()&&this._numericValue<SmartDateYearPart.MINIMAL_VALUE&&(this._numericValue=SmartDateYearPart.MINIMAL_VALUE),this._defineCleanValue()}_defineParsingState(){return 0<this._numericValue&&this._parsedValue.length>=this._size?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}_defineCleanValue(){this._cleanedValue=0<this._numericValue?this._numericValue+"":""}}SmartDateYearPart.MINIMAL_VALUE=1e3,SmartDateYearPart.MAXIMAL_VALUE=9999;class SmartDateParseState{constructor(){this._value="",this._valueIndex=0}start(a){this._value=a,this._valueIndexLine truncated
|
||||
Reference in new issue
Block a user