-
Notifications
You must be signed in to change notification settings - Fork 22
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
Can{t get model with a FormGroup inside a FormArray inside a nested FormGroup #154
Comments
So, I simple it down to this: part 'user_profile.freezed.dart';
part 'user_profile.g.dart';
part 'user_profile.gform.dart';
/// [UserProfile] model
@freezed
@ReactiveFormAnnotation()
class UserProfile with _$UserProfile, BaseUser, NexusElement, RestrictedPermissions {
const UserProfile._();
/// Factory constructor
/// [id] - [UserProfile] id
@JsonSerializable(fieldRename: FieldRename.snake, explicitToJson: true)
const factory UserProfile({
required String id,
//
@FormControlAnnotation(validators: [RequiredValidator()]) required String name,
//
@JsonKey(name: "pass")
@FormControlAnnotation(validators: [RequiredValidator()])
required String passwordHash,
//
@JsonKey(
name: 'perm',
fromJson: _userProfilePermissionsFromJson,
toJson: _userProfilePermissionsToJson,
)
@FormArrayAnnotation()
required List<PermissionEntity> permissions,
//
@JsonKey(name: "bdte", fromJson: fromJsonTimestamp, toJson: toJsonTimestamp)
@FormControlAnnotation()
required DateTime? birthDate,
//
@JsonKey(name: "tel") @FormControlAnnotation() required int? phoneNumber,
}) = _UserProfile;
/// Serialization
factory UserProfile.fromJson(Map<String, dynamic> json) => _$UserProfileFromJson(json);
bool validate(String enteredPassword) {
return Crypt(passwordHash).match(enteredPassword);
}
}
@FormGroupAnnotation()
class PermissionEntity {
PermissionEntity({
@FormControlAnnotation() required this.permission,
@FormControlAnnotation() required this.value,
});
final ProfilePermissionsEnum permission;
final bool value;
} Now if I try to print the model it works. But I can't build the ReactiveFormArray<Map<String, Object?>>(
formArray: formModel.permissionsControl,
builder: (context, formArray, child) {
return Column(
children: formModel.permissionsControl.controls
.asMap()
.map((i, deliveryPoint) {
return MapEntry(
i,
Column(
children: [
ReactiveCheckbox(
formControlName: '${i}.value',
),
],
),
);
})
.values
.toList(),
);
},
), The problem is that it won't find the Am I doing something worng? I'm using:
|
im facing the same issue. @fershous have you found any solution? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here are the models:
The problem is that the
PermissionEntity
is being created as aFormControl<Map<String, Object?>>
and it won't read it as aFormGroup
. Unless I'm doing something wrong, I think there's something bad happening.I have used
FormArrays
asFormGroup
s and indeed it read it asFormControl<Map<String, Object?>>
but it works if I just cast it asFormGroup
maybe a cast is missing when getting the value.The text was updated successfully, but these errors were encountered: