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
Bug with a custom pattern on Date mask #100
Comments
@caiotarifa you have to provide your custom |
Yes, I read the documentation. I only want to replace the |
@caiotarifa Still It does not make sense to put it into mask library. Btw I believe that I even should not had to add default pattern with dots. I try to keep library size as small as possible and who does not care about size almost always use |
Hi, I am having the same problem despite adding parse and format returns '2018-10-2' in input. Always leaves the last digit off. Other than this I am very impressed with the program mask: Date, |
@TonyE73 please also provide your |
OK, it is sorted. I just followed your instructions mask: Date, |
@TonyE73 Check it works https://jsfiddle.net/o9gaydq8/ |
@uNmAnNeR this solution is a hack and does not work like the other behaviour - please reopen and say this is a temporary workaround |
The problem still exists. I have the same problem with the date pattern right now. |
Hi, This setting using luxon works for me. It seems that the problem of last digit when an error occurs during the format or parse function. import { DateTime } from "luxon";
const patternDate = 'dd/LL/yyyy';
const mask = {
mask: Date,
pattern: patternDate,
format: function (date) {
return date.toLocaleString(patternDate);
},
parse: function (str) {
return DateTime.fromFormat(str, patternDate);
},
blocks: {
yyyy: {
mask: IMask.MaskedRange,
from: 1900,
to: 2090,
},
LL: {
mask: IMask.MaskedRange,
from: 1,
to: 12,
},
dd: {
mask: IMask.MaskedRange,
from: 1,
to: 31,
},
},
}; |
Why is this issue closed if the problem is not fixed? |
Just got the same issue in import { IMaskTextInput } from 'react-native-imask';
import { format, parse } from 'date-fns';
const DateInput = () => {
return (
<IMaskTextInput
mask={Date}
pattern="m{/}`d{/}`Y"
format={(date: Date): string => format(date, 'MM/dd/yyyy')}
parse={(value: string): Date => parse(value, 'MM/dd/yyyy', new Date())}
/>
);
}; Hope it will help someone! |
I solved it by changing the imask-6.4.3.js file, starting from line 2766 to 2784. New code:
|
keeps closing with the problem not being solved... |
@fellipefreiire i feel like the only problem here is that people are just do not want to read the docs. There is a way to extend the mask with any date/time pattern but instead of trying to figure it out people prefer to blame in the comments to make me do their work. Let me know if i am wrong and you or someone else has a real issue related to the library facilities that does not allow you to solve your problem. Otherwise i will continue to respectfully ignore these throws. |
I faced the similar issue and found this thread. If I got it right, the problem is that if I provide any custom @uNmAnNeR Maybe, docs should be a little bit more specific on this. Wouldn't it better to add typings constraints disallowing to pass non-default |
@ezze good idea about types, will check |
@uNmAnNeR Ha-ha, some lads including me should buy vision glasses. :) Although I was pretty sure that read the docs carefully. Just for reference: https://imask.js.org/guide.html#masked-date |
I see where the confusion was, in the parse function you also have to realign your split date string accordingly. Typing the variables also helps, especially for date logic. Although, I used :any when passing into format
|
Hi. I prefer use dayjs for format and parse: import dayjs from "dayjs";
import { IMask, IMaskInput } from "react-imask";
const configDate = () => ({
d: {
mask: IMask.MaskedRange,
from: 1,
to: 31,
maxLength: 2,
},
m: {
mask: IMask.MaskedRange,
from: 1,
to: 12,
maxLength: 2,
},
Y: {
mask: IMask.MaskedRange,
from: 1919,
to: 2030,
maxLength: 4,
},
});
const configTime = () => ({
H: {
mask: IMask.MaskedRange,
from: 0,
to: 23,
},
i: {
mask: IMask.MaskedRange,
from: 0,
to: 59,
},
});
const momentFormat = "YYYY-MM-DD HH:mm";
const DateTimeInput = () => {
const date = configDate( );
const time = configTime();
const dateBlocks = {
...date,
separator: "-",
};
const timeBlocks = {
...time,
separator: ":",
};
return (
<IMaskInput
mask={Date as any}
inputRef={ref}
lazy={false}
pattern="Y-m-d H:i"
autofix={true}
blocks={{
...dateBlocks,
...timeBlocks,
}}
onAccept={onChange}
value={value}
format={(date) => dayjs(date).format(momentFormat)}
parse={(str) => dayjs(str, momentFormat)}
placeholder={placeholder}
/>
)
} |
The user can't type the last number when I change the pattern to
d/m/Y
.new IMask(element, { mask: Date, pattern: 'd/m/Y' })
Browser: Safari 11
Demo: https://jsfiddle.net/p2Lt5j3b/1/
The text was updated successfully, but these errors were encountered: