Skip to content

Commit

Permalink
version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sanniassin committed Feb 8, 2018
1 parent 5277167 commit fe93c48
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions dist/react-input-mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,15 @@ function formatValue(maskOptions, value) {

if (!maskChar) {
value = insertString(maskOptions, '', value, 0);
value = value.slice(0, getFilledLength(maskOptions, value));

if (value.length < prefix.length) {
value = prefix;
}

while (value.length < mask.length && isPermanentChar(maskOptions, value.length)) {
value += mask[value.length];
}

return value;
}

Expand All @@ -259,6 +262,13 @@ function clearRange(maskOptions, value, start, len) {
var arrayValue = value.split('');

if (!maskChar) {
// remove any permanent chars after clear range, they will be added back by foramtValue
for (var i = end; i < arrayValue.length; i++) {
if (isPermanentChar(maskOptions, i)) {
arrayValue[i] = '';
}
}

start = Math.max(prefix.length, start);
arrayValue.splice(start, end - start);
value = arrayValue.join('');
Expand Down Expand Up @@ -443,7 +453,7 @@ function (_React$Component) {
var newValue = this.hasValue ? this.getStringValue(nextProps.value) : this.value;

if (!oldMaskOptions.mask && !this.hasValue) {
newValue = this.getInputDOMNode().value;
newValue = this.getInputValue();
}

if (isMaskChanged || this.maskOptions.mask && (newValue || showEmpty)) {
Expand Down Expand Up @@ -821,6 +831,10 @@ var _initialiseProps = function _initialiseProps() {
var editablePos = deleteFromRight ? _this3.getRightEditablePos(cursorPos) : _this3.getLeftEditablePos(cursorPos - 1);

if (editablePos !== null) {
if (!maskChar) {
value = value.substr(0, getFilledLength(_this3.maskOptions, value));
}

value = clearRange(_this3.maskOptions, value, editablePos, 1);
cursorPos = editablePos;
}
Expand Down
Loading

0 comments on commit fe93c48

Please sign in to comment.