-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change the placeholder char #49
Comments
I'm trying to do the same thing... If you found the solution, please share it ! |
Here is what I did....
function InputMask(options) {
if (!(this instanceof InputMask)) { return new InputMask(options) }
options = extend({
formatCharacters: null,
pattern: null,
isRevealingMask: false,
placeholderChar: DEFAULT_PLACEHOLDER_CHAR,
selection: {start: 0, end: 0},
value: ''
}, options)
if (options.pattern == null) {
throw new Error('InputMask: you must provide a pattern.')
}
/* remove the validation
if (typeof options.placeholderChar !== 'string' || options.placeholderChar.length > 1) {
throw new Error('InputMask: placeholderChar should be a single character or an empty string.')
}
*/
// change placeholderChar to be an array:
this.placeholderChar = (Array.isArray(options.placeholderChar) ? options.placeholderChar : Array(options.pattern.length+1).join(options.placeholderChar))
this.formatCharacters = mergeFormatCharacters(options.formatCharacters)
this.setPattern(options.pattern, {
value: options.value,
selection: options.selection,
isRevealingMask: options.isRevealingMask
})
} Pattern.prototype.formatValue = function format(value) {
var valueBuffer = new Array(this.length)
var valueIndex = 0
for (var i = 0, l = this.length; i < l; i++) {
if (this.isEditableIndex(i)) {
if (this.isRevealingMask &&
value.length <= valueIndex &&
!this.isValidAtIndex(value[valueIndex], i)) {
break
}
valueBuffer[i] = (value.length > valueIndex && this.isValidAtIndex(value[valueIndex], i)
? this.transform(value[valueIndex], i)
: this.placeholderChar[i]) // we want to show the rest of the mask
valueIndex++
}
else {
valueBuffer[i] = this.pattern[i]
// Also allow the value to contain static values from the pattern by
// advancing its index.
if (value.length > valueIndex && value[valueIndex] === this.pattern[i]) {
valueIndex++
}
}
}
return valueBuffer;
}
InputMask.prototype.input = function input(char) {
[...]
var end = this.selection.end - 1
while (end > inputIndex) {
if (this.pattern.isEditableIndex(end)) {
this.value[end] = this.placeholderChar[end] // placeholderChar is now an array
}
end--
}
[...]
} Same thing with InputMask.prototype.backspace = function backspace() {
[...]
if (this.selection.start === this.selection.end) {
if (this.pattern.isEditableIndex(this.selection.start - 1)) {
if(this.pattern.isRevealingMask){
this.value.splice(this.selection.start - 1)
} else {
this.value[this.selection.start - 1] = this.placeholderChar[this.selection.start - 1] // placeholderChar is now an array
}
}
this.selection.start--
this.selection.end--
}
else {
var end = this.selection.end - 1
while (end >= this.selection.start) {
if (this.pattern.isEditableIndex(end)) {
this.value[end] = this.placeholderChar[end] // placeholderChar is now an array
}
end--
}
this.selection.end = this.selection.start
}
}
placeholderChar: {
/*type: String,*/
default: '_',
/*validator: function validator(value) {
return !!(value && value.length === 1);
}*/
},
<masked-input
type="text"
mask="1111-11-11"
placeholder="YYYY-MM-DD"
:placeholder-char="'YYYY-MM-DD'.split('')"
v-model="date"></masked-input> |
here is what i did
3.
|
Hi, i try to use this component and it awsome.
now i need to do something in addition and i want to know if there is easy way to do it.
I need to replace the placeholder char with something that is more then 1 char.
the component before focus:
after focus:
while texting:
how can i replace the single placeholderChar '_' with this string dd/mm/yyyy
The text was updated successfully, but these errors were encountered: