Skip to content

Commit 7636fcf

Browse files
committed
Time docs
1 parent 6d50755 commit 7636fcf

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

lib/src/form_builder_validators.dart

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,34 @@ class FormBuilderValidators {
504504
: null;
505505

506506
/// [FormFieldValidator] that requires the field's value to be a valid time string.
507-
/// * [errorText] is the error message to display when the time is invalid
508-
/// Valid time formats are `HH:mm:ss`, `HH:mm` and `HH:mm:ss.SSS` (24-hour clock)
509-
/// and `h:mm:ss a`, `h:mm a` and `h:mm:ss.SSS a` (12-hour clock)
507+
///
508+
/// The validator supports various time formats, both 24-hour and 12-hour clocks.
509+
///
510+
/// ## Valid 24-hour time formats:
511+
/// - `HH:mm`: Hours and minutes, e.g., `23:59`
512+
/// - `HH:mm:ss`: Hours, minutes, and seconds, e.g., `23:59:59`
513+
/// - `HH:mm:ss.SSS`: Hours, minutes, seconds, and milliseconds, e.g., `23:59:59.999`
514+
///
515+
/// ## Valid 12-hour time formats:
516+
/// - `h:mm a`: Hours and minutes with AM/PM, e.g., `11:59 PM`
517+
/// - `h:mm:ss a`: Hours, minutes, and seconds with AM/PM, e.g., `11:59:59 PM`
518+
/// - `h:mm:ss.SSS a`: Hours, minutes, seconds, and milliseconds with AM/PM, e.g., `11:59:59.999 PM`
519+
///
520+
/// ## Parameters:
521+
/// - [errorText] (optional): The error message to display when the time is invalid.
522+
///
523+
/// ## Returns:
524+
/// A validator that checks if the field's value is a valid time string. If the value is null, empty, or not a valid time, it returns the [errorText] or a default error message.
525+
///
526+
/// Example usage:
527+
/// ```dart
528+
/// FormBuilderTextField(
529+
/// name: 'time',
530+
/// validator: FormBuilderValidators.time(errorText: 'Invalid time format'),
531+
/// )
532+
/// ```
533+
///
534+
/// If the [errorText] parameter is not provided, a default error message is used.
510535
static FormFieldValidator<String> time({
511536
String? errorText,
512537
}) =>

0 commit comments

Comments
 (0)