From 51a49588437ada82b820291e5b9743b4520e34ae Mon Sep 17 00:00:00 2001 From: Maximilian Betz <Maximilian.Betz@awi.de> Date: Tue, 1 Mar 2022 14:31:25 +0100 Subject: [PATCH] text input validation halfway done --- lib/addevent.dart | 16 +++++++++++++++- lib/configuration.dart | 8 ++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/addevent.dart b/lib/addevent.dart index 370c4f4..f3e0a50 100644 --- a/lib/addevent.dart +++ b/lib/addevent.dart @@ -124,6 +124,9 @@ class _AddEventPageState extends State<AddEvent> { final EventCurrentInstance currentEvent = EventCurrentInstance(); String gnssStatusText = ""; + final formKey = GlobalKey<FormState>(); //key for form + + if (true == syncGNSSData){ // Update current event coordinates from GNSS stream currentEvent.store.latitude = lat; @@ -149,12 +152,23 @@ class _AddEventPageState extends State<AddEvent> { children: <Widget>[ TextFormField( initialValue: currentEvent.store.label, + autovalidateMode: AutovalidateMode.onUserInteraction, decoration: const InputDecoration( - labelText: 'Label' + labelText: 'Label', + errorText: 'Only: a-z , A-Z , _ , 0-9 , ,(Comma) , ( , ) , + , - , . , :' ), onChanged: (value) { currentEvent.store.label = value; }, + validator: (value){ + if(!RegExp(r'^[a-z A-Z . \- 0-9 , ( ) + - _ :]+$').hasMatch(value!)){ + return "Only: a-z , A-Z , _ , 0-9 , ,(Comma) , ( , ) , + , - , . , :"; + }else{ + currentEvent.store.label = value; + return ''; // Entered Text is valid + } + }, + ), DropdownButtonFormField( value: currentEvent.store.type, diff --git a/lib/configuration.dart b/lib/configuration.dart index 4b8a44d..fad1d0b 100644 --- a/lib/configuration.dart +++ b/lib/configuration.dart @@ -43,6 +43,8 @@ Future<List<Device>> updateDevices(int collectionId) async { Future<List<Collection>> fetchCollections() async { debugPrint("Fetching Collections..."); List<Collection> collectionList = []; + CollectionStoreInstance collections = CollectionStoreInstance(); + final response = await http .get(Uri.parse('https://sensor.awi.de/rest/sensors/collections/getAllCollections?pointInTime=2018-07-03T12%3A30%3A55.389Z')); @@ -73,7 +75,6 @@ class _MyHomePageState extends State<Configuration> { @override void initState() { super.initState(); - //futureCollection = fetchCollection(); futureCollections = fetchCollections(); } late Future<String> eventTypes; @@ -109,10 +110,13 @@ class _MyHomePageState extends State<Configuration> { /*Initialize active collection with first received collection if not initialized yet*/ - if(activeCollection.store.collectionName == ''){ + if(activeCollection.store.id == -1){ activeCollection.store = collections.store[0]; } + print(activeCollection.store); + print(collections.store); + return DropdownButtonFormField( value: activeCollection.store.collectionName, decoration: const InputDecoration( -- GitLab