Skip to content
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

Clear date does not trigger onChange #198

Open
viktoryoo opened this issue Aug 10, 2022 · 0 comments
Open

Clear date does not trigger onChange #198

viktoryoo opened this issue Aug 10, 2022 · 0 comments

Comments

@viktoryoo
Copy link

viktoryoo commented Aug 10, 2022

I've installed react-flatpickr (3.10.13 version) as a dev dependency. When clearing the date via a button, onChange prop does not trigger my custom function. Here's an example of my code:

const TemplateDuration = (props) => {
        const [durationTimeIsFilled, setDurationTimeIsFilled] = useState(false);
	const refFlatpickr = useRef(null);
	
	const onChangeCuttoffTime = (date) => {
		// The chosen date from React Flatpickr is an array.
		if (date && date.length > 0) {
			setDurationTimeIsFilled(true);

			// Some custom logic
		} else if (date.length === 0 && !durationTimeIsFilled) {
			console.log('Clear date');
			
		}
	};

        const clearDate = () => {
		refFlatpickr.current.flatpickr.clear();
		setDurationTimeIsFilled(false);
	};

	return (
	        <div>
			<Flatpickr
				data-testid='input date'
				ref={refFlatpickr}
				options={{
					mode: 'range',
					enableTime: false,
					dateFormat: timeFormat,
					altFormat: timeFormat,
					altInput: true,
					position: 'below',
					parseDate: (dateStr: string, format: string) => {
						return dayjs(dateStr, format).toDate();
					},
					formatDate: (date, format) => {
						// locale can also be used
						return dayjs(date).format(format);
					},
				}}
				onChange={onChangeCuttoffTime}
			/>
			{props.durationTimeIsFilled && (
				<button onClick={clearDate}>
					Clear date
				</button>
			)}
	</div>

Expected result: When clearing date should be logged message "Clear date"
Actual result: There is no logged message.

NOTE: Before updating to 3.10.13 version there was no problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant