-
datePickerMode="single" (default mode)
import { useState } from "react";
import { FormInput } from "react-native-formtastic";
const App = () => {
const [dateOfBirth, setDateOfBirth] = useState<Date>(new Date());
const [dateOfBirthValue, setDateOfBirthValue] = useState<string>("");
return (
<FormInput
labelText="Date of Birth"
isRequired={true}
leftIcon={"calendar"}
datePicker={true} // Use This Prop to Enable The DatePicker
datePickerWithTime={true} // Whether to Include Date With Time
disableFutureDates={true} // Disable Selection of Future Dates
datePlaceholder="Select Date of Birth"
onDateChange={(date: Date) => {
setDateOfBirth(date);
}}
sendDateValue={(dateValue) => {
setDateOfBirthValue(dateValue);
}}
/>
);
};
export default App;
-
datePickerMode="range"
import { useState } from "react";
import { FormInput } from "react-native-formtastic";
const App = () => {
type DateRange = {
startDate: Date;
endDate: Date;
};
const [checkInOutDateRange, setCheckInOutDateRange] = useState<DateRange>({
startDate: new Date(),
endDate: new Date(),
});
type DateRangeValues = {
startDate: string;
endDate: string;
};
const [checkInOutDateRangeValue, setCheckInOutDateRangeValue] = useState<DateRangeValues>({
startDate: '',
endDate: '',
});
return (
<FormInput
labelText="Check In & Check Out Dates"
isRequired={true}
leftIcon={"calendar"}
datePicker={true} // Use This Prop to Enable The DatePicker
disablePastDates={true} // Disable Selection of Past Dates
datePlaceholder="Select Check In & Check Out Dates"
datePickerMode="range" // Required
onDateRangeChange={({ startDate, endDate }) => {
if (startDate && endDate) {
setCheckInOutDateRange({
startDate: startDate,
endDate: endDate,
});
}
}}
sendDateRangeValues={(startDate, endDate) => {
if (startDate && endDate) {
setCheckInOutDateRangeValue({
startDate: startDate,
endDate: endDate,
});
}
}}
/>
);
};
export default App;
-
datePickerMode="multiple"
import { useState } from "react";
import { FormInput } from "react-native-formtastic";
const App = () => {
const [meetingDates, setMeetingDates] = useState<Date[]>([]);
const [meetingDatesValue, setMeetingDatesValue] = useState<string[]>([]);
return (
<FormInput
labelText="Meeting Dates"
isRequired={true}
leftIcon={"calendar"}
datePicker={true} // Use This Prop to Enable The DatePicker
disablePastDates={true} // Disable Selection of Past Dates
datePlaceholder="Select Meeting Dates"
datePickerMode="multiple" // Required
onDatesChange={(dates) => {
if (dates) {
setMeetingDates(dates);
}
}}
sendDatesValues={(dates) => {
if (dates) {
setMeetingDatesValue(dates);
}
}}
/>
);
};
export default App;
The component accepts the following props (Important & useful props are shown first and are in bold) [All props are optional]:
-
value
: Value of the input field.
-
onTextChange
: Function to call when the text changes.
-
labelText
: Text for the label.
-
isRequired
: Boolean to mark the input as required.
-
inputType
: Type of input (e.g., 'default', 'numeric', 'email-address').
-
error
: Boolean to indicate an error state.
-
errorText
: Text to display below input when there is an error.
-
mainContainerStyle
: Style object for the outermost main container.
-
inputContainerStyle
: Style object for the input container.
-
placeholderText
: Placeholder text for the input field.
-
placeholderTextColor
: Color of the placeholder text.
-
inputStyle
: Style object for the input field.
-
inputTextColor
: Color of the input text.
-
hideLabel
: Boolean to hide the label.
-
labelTextStyle
: Style object for the label text.
-
labelTextContainerStyle
: Style object for the label text container.
-
requiredText
: Text to display instead of '*' when the input is required.
-
requiredTextStyle
: Style object for the required text.
-
requiredTextColor
: Color of the required text.
-
labelTextColor
: Color of the label text.
-
textInputProps
: Additional props for the TextInput component.
-
labelTextProps
: Additional props for the label text.
-
requiredTextProps
: Additional props for the required text.
-
mainContainerViewProps
: Additional props for the main container view.
-
inputContainerViewProps
: Additional props for the text input container view.
-
labelTextContainerViewProps
: Additional props for the label text container view.
-
characterLimit
: Maximum number of characters allowed in the input.
-
showCharacterLimit
: Boolean to show the character limit below input field.
-
autoCapitalize
: How to auto capitalize the input (e.g., 'none', 'sentences', 'words', 'characters').
-
errorTextStyle
: Style object for the error text.
-
leftIcon
: Name of the left icon (Icon used: react-native-vector-icons/FontAwesome).
-
leftIconColor
: Color of the left icon.
-
leftIconStyle
: Style object for the left icon.
-
leftIconContainerStyle
: Style object for the left icon container.
-
renderLeftIcon
: Function to render a custom left icon.
-
leftIconOnPress
: Function to call when the left icon is pressed.
-
rightIcon
: Name of the right icon (Icon used: react-native-vector-icons/FontAwesome).
-
rightIconColor
: Color of the right icon.
-
rightIconStyle
: Style object for the right icon.
-
rightIconContainerStyle
: Style object for the right icon container.
-
renderRightIcon
: Function to render a custom right icon.
-
rightIconOnPress
: Function to call when the right icon is pressed.
-
hiddenText
: Boolean to hide the text input (for password fields).
-
disabled
: Boolean to disable the input field.
These are the date picker props (Important & useful props are shown first and are in bold) [All props are optional. For datepicker to work, you need to give the datepicker prop.]:
-
datePicker
: Boolean to enable the date picker functionality.
-
datePickerWithTime
: Boolean to include time in the date picker. It will only work in datePickerMode="single".
-
datePickerMode
: Mode of the date picker (e.g., 'single', 'range', 'multiple').
-
initialDate
: Initial date for the date picker. (For datePickeMode: single)
-
initialRange
: Initial date range for the date picker. (For datePickeMode: range)
-
initialDates
: Initial dates for the date picker. (For datePickeMode: multiple)
-
Usage:
const date_1 = new Date();
const date_2 = new Date(new Date().setDate(new Date().getDate() + 1));
const date_3 = new Date(new Date().setDate(new Date().getDate() + 5));
<FormInput
//.... Other Props
initialDates={[date_1, date_2, date_3]}
//... Other Props
/>
-
onDateChange
: Function to call when the date changes. (For datePickeMode: single)
-
sendDateValue
: Function to call with the selected date value. (For datePickeMode: single)
-
onDateRangeChange
: Function to call when the date range changes. (For datePickeMode: range)
-
Usage:
<FormInput
onDateRangeChange={({ startDate, endDate }) => {
console.log('Start Date: ', startDate);
console.log('End Date: ', endDate);
}}
/>
-
sendDateRangeValues
: Function to call with the selected date range values. (For datePickeMode: range)
-
Usage:
<FormInput
sendDateRangeValues={(startDate, endDate) => {
console.log('Start Date: ', startDate);
console.log('End Date: ', endDate);
}}
/>
-
onDatesChange
: Function to call when the dates change. (For datePickeMode: multiple)
-
sendDatesValues
: Function to call with the selected dates values. (For datePickeMode: multiple)
-
datePlaceholder
: Placeholder text for the date picker. (If you don't give this prop, the selected date will show.)
-
disableFutureDates
: Boolean to disable future dates in the date picker.
-
disablePastDates
: Boolean to disable past dates in the date picker.
-
datePickerBackgroundColor
: Background color for the date picker.
-
showDatePickerCloseButton
: Boolean to show the close button in the date picker.
-
datePickerCloseButtonColor
: Color of the close button in the date picker.
-
selectedItemColor
: Color of the selected item in the date picker.
-
selectedTextStyle
: Style object for the selected text in the date picker.
-
firstDayOfWeek
: First day of the week in the date picker.
-
headerTextContainerStyle
: Style object for the header text container in the date picker.
-
datePickerAnimationType
: Animation type for the date picker (e.g., 'zoomIn', 'slideUp', 'slideDown', slideLeft', 'slideRight', 'none').
-
animationDuration
: Custom animation duration for the transition of date picker modal.
-
hideDatePickerConfirmButton
: Boolean to hide the date picker confirm button.
-
dateFormat
: Custom format for the date / date range / dates.
-
dateTimeFormat
: Custom format for the date and time for single date if datePickerWithTime is selected.