Replies: 45 comments
-
Hi Robert, you have raised a very valid concern and I am totally with you on the complexity of managing this. Your suggestion of The sample API could look like so. Note that the validation itself is outside of the scope of import 'package:mobx/mobx.dart';
part 'observable_form_field.g.dart';
class ObservableFormField<T> = _ObservableFormField<T> with _$ObservableFormField;
class _ObservableFormField<T> with Store {
_ObservableFormField({this.name, this.label, this.value});
final String name;
final String title;
// Most important error
@computed
String get error => errors == null ? null : errors[0];
// All errors, if more than one
@observable
List<String> errors;
@observable
T value;
@computed
bool get isValid => errors == null;
} This is just a start and we can iterate together to create this package ? |
Beta Was this translation helpful? Give feedback.
-
Hi Pavan, A full featured but complementary I'll provide you with all the support I can to setup this package ! |
Beta Was this translation helpful? Give feedback.
-
Awesome. Why don't we start with the use cases you are tackling ? Should I make a branch on this repo for |
Beta Was this translation helpful? Give feedback.
-
Currently I'm working on a POC and creating the use cases for the developers to rely on. Goals is to cover basic types fields, errors management, local & remote validations, sub-forms reactions, etc This could be used as the main example for I'll join you on this new exciting branch. |
Beta Was this translation helpful? Give feedback.
-
Nice. Let me make and invite you |
Beta Was this translation helpful? Give feedback.
-
We might have to include some Observer components too, so I think I should call this |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
abstract class StringField with Store {
StringField(this._validator);
final String Function(String value) _validator;
@observable
String value;
@computed
String get error => _validator?.call(value);
@computed
bool get isValid => error == null;
} Which allows: StringFIeld((value) {
if (value.isEmpty) return "Missing field but required";
return null;
}); |
Beta Was this translation helpful? Give feedback.
-
Agree @rrousselGit. I was also thinking there could be multiple errors for some fields |
Beta Was this translation helpful? Give feedback.
-
We will have to decide if we take a hard dependency on |
Beta Was this translation helpful? Give feedback.
-
Indeed but StringField((value) sync* {
if (value.isEmpty) yield "Missing field but required";
}); assuming we change the @computed
List<String> get error => _validator?.call(value)?.toList() ?? const []; |
Beta Was this translation helpful? Give feedback.
-
What do you mean by hard-dependency here? |
Beta Was this translation helpful? Give feedback.
-
I meant the |
Beta Was this translation helpful? Give feedback.
-
Oh btw: say hello to flutter_mobx_forms...the most underrated package as of now :-) |
Beta Was this translation helpful? Give feedback.
-
I've put in three of us as authors. Robert if you share your email, I'll update |
Beta Was this translation helpful? Give feedback.
-
How about a single |
Beta Was this translation helpful? Give feedback.
-
Or maybe I'm missing a thing ? here's some code
We configure nearly everything in the FieldState and pass it as a parameter to have our widget configured. It's a little rough but you get the idea how we wrap data from state.
And those will configure the Widget. |
Beta Was this translation helpful? Give feedback.
-
Got it. It really looks cool, esp. the annotations for constraints! Would love to have this part of the project, so we all can benefit 🤞 |
Beta Was this translation helpful? Give feedback.
-
Annotations are not here for now but I use this Thread to push and validate ideas like this with the community. |
Beta Was this translation helpful? Give feedback.
-
Awesome! Declarative, annotation driven form development would make it so nice! If possible we can even hide the MobX machinery :-) |
Beta Was this translation helpful? Give feedback.
-
Can you help with this code please The value is well calculated the first time but even is _calculateAge() is called on update,
Widget never rebuild.
Can it be an interference between Provider & MobX ? I've tried with one observer or many none trigger. Thank you ! |
Beta Was this translation helpful? Give feedback.
-
final civilState = Provider.of<UserForm>(context).civilState;
You accessed |
Beta Was this translation helpful? Give feedback.
-
This too is not responding what am I missing ?
|
Beta Was this translation helpful? Give feedback.
-
I think you need to remove the |
Beta Was this translation helpful? Give feedback.
-
Still no luck :/ |
Beta Was this translation helpful? Give feedback.
-
When you switch tabs, there has to be something that is changing inside |
Beta Was this translation helpful? Give feedback.
-
@pavanpodila I add you to the project so you can check we're using MobX Form the way is should ?! Generated is triggered, value is calculated, state value is OK but the field inside Observer does not update. Changing tab and going back does, they both trigger the same events in the same orders in the debug. |
Beta Was this translation helpful? Give feedback.
-
Sure, you can add me :-). Will take me towards end of this week to dig deeper. Have a project deadline on Thu/Fri. |
Beta Was this translation helpful? Give feedback.
-
Any update on this? I see PR, but it's not merged for months. |
Beta Was this translation helpful? Give feedback.
-
Sorry, no progress on this as this is not something I need immediately. Happy to look at a PR though :-) |
Beta Was this translation helpful? Give feedback.
-
I'm going with MobX on my new project which involves a lot of Forms (hundreds) and Fields (10 to 50)
At core MobX solve a lot of concerns but it's not easy to copy the Form example at scale when you have a lot of fields.
There are two stores to handle, values and errors also you should not forget to init disposers.
There's an ObservableList that handle specific modifications and react accordingly.
I'd like to have an ObservableFormField that would handle Fields.
So much handwritten code is really error prone when working on real business forms entries
Thank you for your feedback !
I'm not sure how to architect all this but I'll be happy to find logic per field at one place only.
Beta Was this translation helpful? Give feedback.
All reactions