web-ridge / react-native-paper-dates

Smooth and fast cross platform Material Design date and time picker for React Native Paper
https://www.reactnativepaperdates.com
MIT License
638 stars 162 forks source link

Initial date value #305

Closed soto0 closed 11 months ago

soto0 commented 11 months ago

How do I set the initial value for the DatePickerInput. When I try to do this, when I try to open a modal with a date picker, I get undefined is not a function?

iM-GeeKy commented 11 months ago

Feel free to check out the docs for the DatePickerInput. It has a working example.

soto0 commented 11 months ago

I didn't find a solution in the documentation

github-actions[bot] commented 11 months ago

Hey! Thanks for opening the issue. Can you provide a minimal repro which demonstrates the issue? Posting a snippet of your code in the issue is useful, but it's not usually straightforward to run. A repro will help us debug the issue faster. Please try to keep the repro as small as possible. The easiest way to provide a repro is on snack.expo.dev. If it's not possible to repro it on snack.expo.dev, then you can also provide the repro in a GitHub repository.

soto0 commented 11 months ago

here I am trying to pass the initial value for the date

     useEffect(() => {
        if (item) {
            setValue("date", dayjs(item.date) || undefined, { shouldValidate: false });
        }
    }, [item]);

                     <Controller
                        control={control}
                        name="date"
                        rules={{ required: true }}
                        render={({ field: { onChange, value } }) => (
                            <DatePickerInput
                                label="Дата"
                                value={value}
                                locale="ru"
                                mode="outlined"
                                inputMode="start"
                                withDateFormatInLabel={false}
                                onChange={onChange}
                            />
                        )}
                    />
iM-GeeKy commented 11 months ago

My recommendation would be to get a simplistic example working such as the one in the docs. This would rule out the issue is with your setup in particular. I don't see anything inherently wrong with your code, but it's hard to tell without a reproducible example.

soto0 commented 11 months ago

in the documentation, I see that they are passing undefined, but I don’t see that it shows how to pass any date

iM-GeeKy commented 11 months ago

I updated the snack https://snack.expo.dev/@fitzwabs/react-native-paper-dates-input. It now defaults to todays date.

soto0 commented 11 months ago

this worked for me, thanks!