Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed Text not saved. #61

Closed
JulianSwales opened this issue Jul 10, 2022 · 3 comments
Closed

Typed Text not saved. #61

JulianSwales opened this issue Jul 10, 2022 · 3 comments

Comments

@JulianSwales
Copy link

I have a ReactiveTypeAhead widget for which I want to select from the selections, but if one doesn't match then it will be added as a new value.. I have the field set as Validators.required.. However no matter what I type in the field, it never updates the selection unless I select one of the suggestions.. If I do the same thing with the standard TypeAheadField it works fine as this example shows:

                      textFieldConfiguration: TextFieldConfiguration(
                        keyboardType: TextInputType.emailAddress,
                        decoration: InputDecoration(
                          labelText: 'Email',
                          icon: Icon(Icons.email),
                        ),
                        controller: _typeAheadController,
                      ),
                      suggestionsCallback: (pattern) =>
                          CitiesService.getSuggestions(pattern),
                      itemBuilder: (context, String suggestion) {
                        return ListTile(
                          title: Text(suggestion),
                        );
                      },
                      onSuggestionSelected: (String suggestion) {TypeAheadField(
                      textFieldConfiguration: TextFieldConfiguration(
                        keyboardType: TextInputType.emailAddress,
                        decoration: InputDecoration(
                          labelText: 'Email',
                          icon: Icon(Icons.email),
                        ),
                        controller: _typeAheadController,
                      ),
                      suggestionsCallback: (pattern) =>
                          CitiesService.getSuggestions(pattern),
                      itemBuilder: (context, String suggestion) {
                        return ListTile(
                          title: Text(suggestion),
                        );
                      },
                      onSuggestionSelected: (String suggestion) {
                        _typeAheadController.text = suggestion;
                      },
                      },

I added the above code to the Sample ReactiveTypeAhead example and set the input field to required, and I always got an invalid form if I didn't select an option, but on then TypeAheadField I got either the entered value, or the selected value.  
How can I have a ReactiveTypeAhead field that will accept New data values? The _typeAheadController.text field will still contain the text entered if a selection is not selected.  That does not happen with the ReactiveTypeAhead. Thanks. 
@vasilich6107
Copy link
Contributor

@JulianSwales could you add main.dart file with reproduction of issue

@JulianSwales
Copy link
Author

@vasilich6107 Thanks for all you do within this community.
I have a main.dart available here: https://github.com/JulianSwales/test_riverpod_typeahead with example code in it..
There are two issues:

  1. Enter an email address into the email field, one that does NOT exist in the suggestions (If an email address doesn't exist in the suggestions, then the user would be adding the new member).. Then enter a last name, first name and phone and hit the book button.. It will show the email field as being required, and the form shows as invalid with null in the email field. .
  2. If I select one of the suggestions listed, it returns the Model, instead of the string value resulting in an error.. I'm guessing I'm doing something wrong with the code here, but I don't know how to get the email from the Member model as the value into the field. (The idea here is that the suggestion selected would auto fill the other fields) I only setup the firstName field on the valueChanges listen for the test.

@vasilich6107
Copy link
Contributor

vasilich6107 commented Oct 11, 2022

Hi @JulianSwales
Check reactive_flutter_typeahead 0.7.0
I applied fix inspired by #72
Just pass viewDataTypeFromTextEditingValue and it should work properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants