Unverified Commit 8aca65a9 authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

Include validation for inputOnly mode (#78428)

parent ec8fef65
......@@ -306,7 +306,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
}
void _handleOk() {
if (_entryMode == DatePickerEntryMode.input) {
if (_entryMode == DatePickerEntryMode.input || _entryMode == DatePickerEntryMode.inputOnly) {
final FormState form = _formKey.currentState!;
if (!form.validate()) {
setState(() => _autoValidate = true);
......@@ -972,7 +972,7 @@ class _DateRangePickerDialogState extends State<_DateRangePickerDialog> {
}
void _handleOk() {
if (_entryMode == DatePickerEntryMode.input) {
if (_entryMode == DatePickerEntryMode.input || _entryMode == DatePickerEntryMode.inputOnly) {
final _InputDateRangePickerState picker = _inputPickerKey.currentState!;
if (!picker.validate()) {
setState(() {
......
......@@ -177,6 +177,17 @@ void main() {
});
});
testWidgets('Input only mode should validate date', (WidgetTester tester) async {
initialEntryMode = DatePickerEntryMode.inputOnly;
await prepareDatePicker(tester, (Future<DateTime?> date) async {
// Enter text input mode and type an invalid date to get error.
await tester.enterText(find.byType(TextField), '1234567');
await tester.tap(find.text('OK'));
await tester.pumpAndSettle();
expect(find.text('Invalid format.'), findsOneWidget);
});
});
testWidgets('Switching to input mode resets input error state', (WidgetTester tester) async {
await prepareDatePicker(tester, (Future<DateTime?> date) async {
// Enter text input mode and type an invalid date to get error.
......
......@@ -266,6 +266,20 @@ void main() {
});
});
testWidgets('Input only mode should validate date', (WidgetTester tester) async {
initialEntryMode = DatePickerEntryMode.inputOnly;
errorInvalidText = 'oops';
await preparePicker(tester, (Future<DateTimeRange?> range) async {
await tester.enterText(find.byType(TextField).at(0), '08/08/2014');
await tester.enterText(find.byType(TextField).at(1), '08/08/2014');
expect(find.text(errorInvalidText!), findsNothing);
await tester.tap(find.text('OK'));
await tester.pumpAndSettle();
expect(find.text(errorInvalidText!), findsNWidgets(2));
});
});
testWidgets('Switching to input mode keeps selected date', (WidgetTester tester) async {
await preparePicker(tester, (Future<DateTimeRange?> range) async {
await tester.tap(find.text('12').first);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment