Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilich6107 committed Jan 6, 2025
1 parent af1f11a commit 531a496
Show file tree
Hide file tree
Showing 17 changed files with 378 additions and 33 deletions.
83 changes: 83 additions & 0 deletions packages/generator_tests/test/doc/freezed_class_output_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void main() {
@RfControl(validators: [RequiredValidator()]) String? genderR, {
@RfControl() String? id,
@RfControl(validators: [RequiredValidator()]) String? idR,
@RfControl(validators: [RequiredValidator()]) @Default('') String idR2,
@RfControl<String>() String? name,
@JsonKey(name: 'logo_image') @RfControl<String>() String? logoImage,
@RfControl<double>() double? year,
Expand Down Expand Up @@ -287,6 +288,8 @@ class FreezedClassOForm
static const String idRControlName = "idR";
static const String idR2ControlName = "idR2";
static const String nameControlName = "name";
static const String logoImageControlName = "logoImage";
Expand All @@ -307,6 +310,8 @@ class FreezedClassOForm
String idRControlPath() => pathBuilder(idRControlName);
String idR2ControlPath() => pathBuilder(idR2ControlName);
String nameControlPath() => pathBuilder(nameControlName);
String logoImageControlPath() => pathBuilder(logoImageControlName);
Expand All @@ -321,6 +326,8 @@ class FreezedClassOForm
String get _idRValue => idRControl.value as String;
String get _idR2Value => idR2Control.value as String;
String? get _nameValue => nameControl?.value;
String? get _logoImageValue => logoImageControl?.value;
Expand Down Expand Up @@ -363,6 +370,15 @@ class FreezedClassOForm
}
}
bool get containsIdR2 {
try {
form.control(idR2ControlPath());
return true;
} catch (e) {
return false;
}
}
bool get containsName {
try {
form.control(nameControlPath());
Expand Down Expand Up @@ -398,6 +414,8 @@ class FreezedClassOForm
Map<String, Object>? get idRErrors => idRControl.errors;
Map<String, Object> get idR2Errors => idR2Control.errors;
Map<String, Object>? get nameErrors => nameControl?.errors;
Map<String, Object>? get logoImageErrors => logoImageControl?.errors;
Expand All @@ -412,6 +430,8 @@ class FreezedClassOForm
void get idRFocus => form.focus(idRControlPath());
void get idR2Focus => form.focus(idR2ControlPath());
void get nameFocus => form.focus(nameControlPath());
void get logoImageFocus => form.focus(logoImageControlPath());
Expand Down Expand Up @@ -636,6 +656,15 @@ class FreezedClassOForm
updateParent: updateParent, emitEvent: emitEvent);
}
void idR2ValueUpdate(
String value, {
bool updateParent = true,
bool emitEvent = true,
}) {
idR2Control.updateValue(value,
updateParent: updateParent, emitEvent: emitEvent);
}
void nameValueUpdate(
String? value, {
bool updateParent = true,
Expand Down Expand Up @@ -699,6 +728,15 @@ class FreezedClassOForm
updateParent: updateParent, emitEvent: emitEvent);
}
void idR2ValuePatch(
String value, {
bool updateParent = true,
bool emitEvent = true,
}) {
idR2Control.patchValue(value,
updateParent: updateParent, emitEvent: emitEvent);
}
void nameValuePatch(
String? value, {
bool updateParent = true,
Expand Down Expand Up @@ -786,6 +824,21 @@ class FreezedClassOForm
disabled: disabled,
);
void idR2ValueReset(
String value, {
bool updateParent = true,
bool emitEvent = true,
bool removeFocus = false,
bool? disabled,
}) =>
idR2Control.reset(
value: value,
updateParent: updateParent,
emitEvent: emitEvent,
removeFocus: removeFocus,
disabled: disabled,
);
void nameValueReset(
String? value, {
bool updateParent = true,
Expand Down Expand Up @@ -844,6 +897,9 @@ class FreezedClassOForm
FormControl<String> get idRControl =>
form.control(idRControlPath()) as FormControl<String>;
FormControl<String> get idR2Control =>
form.control(idR2ControlPath()) as FormControl<String>;
FormControl<String>? get nameControl => containsName
? form.control(nameControlPath()) as FormControl<String>?
: null;
Expand Down Expand Up @@ -928,6 +984,24 @@ class FreezedClassOForm
}
}
void idR2SetDisabled(
bool disabled, {
bool updateParent = true,
bool emitEvent = true,
}) {
if (disabled) {
idR2Control.markAsDisabled(
updateParent: updateParent,
emitEvent: emitEvent,
);
} else {
idR2Control.markAsEnabled(
updateParent: updateParent,
emitEvent: emitEvent,
);
}
}
void nameSetDisabled(
bool disabled, {
bool updateParent = true,
Expand Down Expand Up @@ -996,6 +1070,7 @@ class FreezedClassOForm
return FreezedClassOOutput(_genderValue, _genderRValue,
id: _idValue,
idR: _idRValue,
idR2: _idR2Value,
name: _nameValue,
logoImage: _logoImageValue,
year: _yearValue);
Expand Down Expand Up @@ -1116,6 +1191,13 @@ class FreezedClassOForm
asyncValidatorsDebounceTime: 250,
disabled: false,
touched: false),
idR2ControlName: FormControl<String>(
value: freezedClassO?.idR2,
validators: [RequiredValidator()],
asyncValidators: [],
asyncValidatorsDebounceTime: 250,
disabled: false,
touched: false),
nameControlName: FormControl<String>(
value: freezedClassO?.name,
validators: [],
Expand Down Expand Up @@ -1152,6 +1234,7 @@ class FreezedClassOOutput with _$FreezedClassOOutput {
@RfControl(validators: [RequiredValidator()]) String genderR,
{@RfControl() String? id,
@RfControl(validators: [RequiredValidator()]) required String idR,
@RfControl(validators: [RequiredValidator()]) required String idR2,
@RfControl<String>() String? name,
@JsonKey(name: 'logo_image') @RfControl<String>() String? logoImage,
@RfControl<double>() double? year}) = _FreezedClassOOutput;
Expand Down
22 changes: 17 additions & 5 deletions packages/generator_tests/test/doc/login_output_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ void main() {
}
}
@Rf(output: true)
class RequiredValidator2 extends RequiredValidator {
const RequiredValidator2() : super();
}
@Rf(
output: true,
requiredValidators: [
...defaultRequiredValidators,
'RequiredValidator2()',
],
)
@RfGroup(
validators: [MustMatchValidator()],
)
Expand All @@ -45,7 +55,7 @@ void main() {
)
this.email,
@RfControl(
validators: [RequiredValidator()],
validators: [RequiredValidator2()],
)
this.password,
});
Expand Down Expand Up @@ -595,7 +605,7 @@ class LoginOForm implements FormModel<LoginO, LoginOOutput> {
touched: false),
passwordControlName: FormControl<String>(
value: loginO?.password,
validators: [RequiredValidator()],
validators: [RequiredValidator2()],
asyncValidators: [],
asyncValidatorsDebounceTime: 250,
disabled: false,
Expand All @@ -609,15 +619,17 @@ class LoginOForm implements FormModel<LoginO, LoginOOutput> {
disabled: false);
}
@Rf(output: true)
@Rf(
output: true,
requiredValidators: [...defaultRequiredValidators, 'RequiredValidator2()'])
@RfGroup(validators: [MustMatchValidator()])
class LoginOOutput extends Equatable {
final String email;
final String password;
const LoginOOutput(
{@RfControl(validators: [RequiredValidator(), RequiredValidator()])
required this.email,
@RfControl(validators: [RequiredValidator()]) required this.password});
@RfControl(validators: [RequiredValidator2()]) required this.password});
@override
List<Object?> get props => [email, password];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/reactive_forms_annotations/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: reactive_forms_annotations
description: Annotations for reactive_forms_generator
repository: https://github.com/artflutter/reactive_forms_generator

version: 6.0.0-beta.7
version: 6.0.0-beta.8

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
8 changes: 8 additions & 0 deletions packages/reactive_forms_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [6.0.0-beta.24]

* bugfix

## [6.0.0-beta.23]

* requiredValidators bugfix

## [6.0.0-beta.22]

* requiredValidators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FreezedClassO with _$FreezedClassO {
@RfControl(validators: [RequiredValidator()]) String? genderR, {
@RfControl() String? id,
@RfControl(validators: [RequiredValidator()]) String? idR,
@RfControl(validators: [RequiredValidator()]) @Default('') String idR2,
@RfControl<String>() String? name,
@JsonKey(name: 'logo_image') @RfControl<String>() String? logoImage,
@RfControl<double>() double? year,
Expand Down
Loading

0 comments on commit 531a496

Please sign in to comment.