Skip to content

Commit

Permalink
docs: Changed the specification of the validator of Form.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Mar 19, 2024
1 parent feaa71e commit 422e156
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 32 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -913,19 +913,19 @@ FormTextField(
),
```

After writing the form widget while including the above process, the form values are validated and confirmed by executing `formController.validateAndSave` when the confirm button is pressed.
After writing the form widget while including the above process, the form values are validated and confirmed by executing `formController.validate` when the confirm button is pressed.

Then, after the validation passes, use `formController.value` to obtain the value and perform the saving process, etc.
After the verification passes, use the returned value to save the data.

```dart
FormButton(
"Login",
onPressed: () async {
if (!formController.validateAndSave()) {
final LoginValue loginValue = formController.validate(); // Validate and get form values
if (loginValue == null) {
return;
}
try {
final LoginValue loginValue = formController.value; // Get form values
// Normal processing
} catch (e) {
// Error handling
Expand Down
38 changes: 21 additions & 17 deletions packages/katana_form/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ return Scaffold(
"Submit",
icon: Icon(Icons.check),
onPressed: () {
if (!form.validateAndSave()) {
final value = form.validate(); // Validate and get form values
if (value == null) {
return;
}
print(form.value);
// Save form.value as is.
print(value);
// Save value as is.
},
),
]
Expand Down Expand Up @@ -139,20 +140,21 @@ FormTextField(

## Form Validation and Storage

`FormController.validateAndSave` can be executed to validate and save the form.
You can validate and save a form by executing `FormController.validate`.

Validation is performed first, and `false` is returned in case of failure.
Validation is performed first, and `null` is returned in case of failure.

If successful, `true` is returned and `FormController.value` is populated with the value changed by `onSaved` of each FormWidget.
If it succeeds, it returns the value changed by `onSaved` of each `Form` widget.

Please update the database based on that value.
Update the database based on that value.

```dart
if (!form.validateAndSave()) {
return;
final value = form.validate(); // Validate and get form values
if (value == null) {
return;
}
print(form.value);
// Save form.value as is.
print(value);
// Save value as is.
```

## Sample code
Expand Down Expand Up @@ -203,11 +205,12 @@ class FormPageState extends State<FormPage> {
"Submit",
icon: Icon(Icons.add),
onPressed: () {
if (!form.validateAndSave()) {
final value = form.validate(); // Validate and get form values
if (value == null) {
return;
}
print(form.value);
// Save form.value as is.
print(value);
// Save value as is.
},
),
],
Expand Down Expand Up @@ -269,11 +272,12 @@ class FormPageState extends State<FormPage> {
"Submit",
icon: Icon(Icons.add),
onPressed: () {
if (!form.validateAndSave()) {
final value = form.validate(); // Validate and get form values
if (value == null) {
return;
}
print(form.value);
// Save form.value as is.
print(value);
// Save value as is.
},
),
],
Expand Down
3 changes: 2 additions & 1 deletion packages/katana_form/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class FormPageState extends State<FormPage> {
"Submit",
icon: const Icon(Icons.add),
onPressed: () {
if (!form.validateAndSave()) {
final value = form.validate(); // Validate and get form values
if (value == null) {
return;
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/masamune/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -913,19 +913,19 @@ FormTextField(
),
```

After writing the form widget while including the above process, the form values are validated and confirmed by executing `formController.validateAndSave` when the confirm button is pressed.
After writing the form widget while including the above process, the form values are validated and confirmed by executing `formController.validate` when the confirm button is pressed.

Then, after the validation passes, use `formController.value` to obtain the value and perform the saving process, etc.
After the verification passes, use the returned value to save the data.

```dart
FormButton(
"Login",
onPressed: () async {
if (!formController.validateAndSave()) {
final LoginValue loginValue = formController.validate(); // Validate and get form values
if (loginValue == null) {
return;
}
try {
final LoginValue loginValue = formController.value; // Get form values
// Normal processing
} catch (e) {
// Error handling
Expand Down
6 changes: 3 additions & 3 deletions packages/masamune_annotation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -915,17 +915,17 @@ FormTextField(

After writing the form widget while including the above process, the form values are validated and confirmed by executing `formController.validateAndSave` when the confirm button is pressed.

Then, after the validation passes, use `formController.value` to obtain the value and perform the saving process, etc.
After the verification passes, use the returned value to save the data.

```dart
FormButton(
"Login",
onPressed: () async {
if (!formController.validateAndSave()) {
final LoginValue loginValue = formController.validate(); // Validate and get form values
if (loginValue == null) {
return;
}
try {
final LoginValue loginValue = formController.value; // Get form values
// Normal processing
} catch (e) {
// Error handling
Expand Down
6 changes: 3 additions & 3 deletions packages/masamune_builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -915,17 +915,17 @@ FormTextField(

After writing the form widget while including the above process, the form values are validated and confirmed by executing `formController.validateAndSave` when the confirm button is pressed.

Then, after the validation passes, use `formController.value` to obtain the value and perform the saving process, etc.
After the verification passes, use the returned value to save the data.

```dart
FormButton(
"Login",
onPressed: () async {
if (!formController.validateAndSave()) {
final LoginValue loginValue = formController.validate(); // Validate and get form values
if (loginValue == null) {
return;
}
try {
final LoginValue loginValue = formController.value; // Get form values
// Normal processing
} catch (e) {
// Error handling
Expand Down

0 comments on commit 422e156

Please sign in to comment.