|
15 | 15 | - [Date and Time Fields](#date-and-time-fields "Date and Time Fields") |
16 | 16 | - [Password Fields](#password-fields "Password Fields") |
17 | 17 | - [Masked Input Fields](#masked-input-fields "Masked Input Fields") |
| 18 | + - [Checkbox Fields](#checkbox-fields "Checkbox Fields") |
| 19 | + - [Picker Fields](#picker-fields "Picker Fields") |
| 20 | + - [Radio Fields](#radio-fields "Radio Fields") |
| 21 | + - [Chip Fields](#chip-fields "Chip Fields") |
| 22 | + - [Switch Box Fields](#switch-box-fields "Switch Box Fields") |
18 | 23 | - [Form Validation](#form-validation "Form Validation") |
19 | 24 | - [Form Casts](#form-casts "Form Casts") |
20 | 25 | - [Managing Form Data](#managing-form-data "Managing Form Data") |
| 26 | +- [Submit Button](#submit-button "Submit Button") |
21 | 27 | - [Form Styling](#form-styling "Form Styling") |
22 | 28 | - [Advanced Features](#advanced-features "Advanced Features") |
23 | 29 | - [Form Layout](#form-layout "Form Layout") |
@@ -248,6 +254,7 @@ Field("Price", cast: FormCast.currency("usd")) |
248 | 254 | // Recommended approach |
249 | 255 | Field.picker("Category", options: ["Electronics", "Clothing", "Books"]), |
250 | 256 | Field.chips("Tags", options: ["Featured", "Sale", "New"]), |
| 257 | +Field.radio("Size", options: ["Small", "Medium", "Large"]), |
251 | 258 |
|
252 | 259 | // Alternative approach |
253 | 260 | Field("Category", |
@@ -319,6 +326,83 @@ Field("Phone", |
319 | 326 | ) |
320 | 327 | ``` |
321 | 328 |
|
| 329 | +<a name="checkbox-fields"></a> |
| 330 | +<br> |
| 331 | + |
| 332 | +### Checkbox Fields |
| 333 | + |
| 334 | +```dart |
| 335 | +// Recommended approach |
| 336 | +Field.checkbox("Accept Terms"), |
| 337 | +
|
| 338 | +// Alternative approach |
| 339 | +Field("Accept Terms", cast: FormCast.checkbox()) |
| 340 | +``` |
| 341 | + |
| 342 | +<a name="picker-fields"></a> |
| 343 | +<br> |
| 344 | + |
| 345 | +### Picker Fields |
| 346 | + |
| 347 | +```dart |
| 348 | +// Recommended approach |
| 349 | +Field.picker("Category", options: ["Electronics", "Clothing", "Books"]), |
| 350 | +
|
| 351 | +// Alternative approach |
| 352 | +Field("Category", |
| 353 | + cast: FormCast.picker( |
| 354 | + options: ["Electronics", "Clothing", "Books"] |
| 355 | + ) |
| 356 | +) |
| 357 | +``` |
| 358 | + |
| 359 | +<a name="radio-fields"></a> |
| 360 | +<br> |
| 361 | + |
| 362 | +### Radio Fields |
| 363 | + |
| 364 | +```dart |
| 365 | +// Recommended approach |
| 366 | +Field.radio("Size", options: ["Small", "Medium", "Large"]), |
| 367 | +
|
| 368 | +// Alternative approach |
| 369 | +Field("Size", |
| 370 | + cast: FormCast.radio( |
| 371 | + options: ["Small", "Medium", "Large"] |
| 372 | + ) |
| 373 | +) |
| 374 | +``` |
| 375 | + |
| 376 | +<a name="chip-fields"></a> |
| 377 | +<br> |
| 378 | + |
| 379 | +### Chip Fields |
| 380 | + |
| 381 | +```dart |
| 382 | +// Recommended approach |
| 383 | +Field.chips("Tags", options: ["Featured", "Sale", "New"]), |
| 384 | +
|
| 385 | +// Alternative approach |
| 386 | +Field("Tags", |
| 387 | + cast: FormCast.chips( |
| 388 | + options: ["Featured", "Sale", "New"] |
| 389 | + ) |
| 390 | +) |
| 391 | +``` |
| 392 | + |
| 393 | +<a name="switch-box-fields"></a> |
| 394 | +<br> |
| 395 | + |
| 396 | +### Switch Box Fields |
| 397 | + |
| 398 | +```dart |
| 399 | +// Recommended approach |
| 400 | +Field.switchBox("Enable Notifications"), |
| 401 | +
|
| 402 | +// Alternative approach |
| 403 | +Field("Enable Notifications", cast: FormCast.switchBox()) |
| 404 | +``` |
| 405 | + |
322 | 406 | <a name="form-validation"></a> |
323 | 407 | <br> |
324 | 408 |
|
@@ -542,6 +626,105 @@ form.clear(); |
542 | 626 | form.clearField("name"); |
543 | 627 | ``` |
544 | 628 |
|
| 629 | +<a name="submit-button"></a> |
| 630 | +<br> |
| 631 | + |
| 632 | +## Submit Button |
| 633 | + |
| 634 | +In your Form class, you can define a submit button: |
| 635 | + |
| 636 | +```dart |
| 637 | +class UserInfoForm extends NyFormData { |
| 638 | + UserInfoForm({String? name}) : super(name ?? "user_info"); |
| 639 | +
|
| 640 | + @override |
| 641 | + fields() => [ |
| 642 | + Field.text("First Name", |
| 643 | + style: "compact" |
| 644 | + ), |
| 645 | + Field.text("Last Name", |
| 646 | + style: "compact" |
| 647 | + ), |
| 648 | + Field.number("Phone Number", |
| 649 | + style: "compact" |
| 650 | + ), |
| 651 | + ]; |
| 652 | + |
| 653 | + @override |
| 654 | + Widget? get submitButton => Button.primary(text: "Submit", |
| 655 | + submitForm: (this, (data) { |
| 656 | + printInfo(data); |
| 657 | + })); |
| 658 | +} |
| 659 | +``` |
| 660 | + |
| 661 | +The `Button` widget is a pre-built component that can be used to submit a form. |
| 662 | +All you need to do is pass the `submitForm` parameter to the button. |
| 663 | + |
| 664 | +Out the box, Nylo provides 8 pre-built buttons that you can use to submit a form. |
| 665 | +- `Button.primary` |
| 666 | +- `Button.secondary` |
| 667 | +- `Button.outlined` |
| 668 | +- `Button.textOnly` |
| 669 | +- `Button.icon` |
| 670 | +- `Button.gradient` |
| 671 | +- `Button.rounded` |
| 672 | + |
| 673 | +If you want to use a different widget to submit the form, you can call the `submit` method on the form: |
| 674 | + |
| 675 | +```dart |
| 676 | +class UserInfoForm extends NyFormData { |
| 677 | + UserInfoForm({String? name}) : super(name ?? "user_info"); |
| 678 | +
|
| 679 | + @override |
| 680 | + fields() => [ |
| 681 | + Field.text("First Name", |
| 682 | + style: "compact" |
| 683 | + ), |
| 684 | + Field.text("Last Name", |
| 685 | + style: "compact" |
| 686 | + ), |
| 687 | + Field.number("Phone Number", |
| 688 | + style: "compact" |
| 689 | + ), |
| 690 | + ]; |
| 691 | + |
| 692 | + @override |
| 693 | + Widget? get submitButton => ElevatedButton( |
| 694 | + onPressed: () { |
| 695 | + submit(onSuccess: (data) { |
| 696 | + printInfo(data); |
| 697 | + }); |
| 698 | + }, |
| 699 | + child: Text("Submit"), |
| 700 | + ); |
| 701 | +} |
| 702 | +``` |
| 703 | + |
| 704 | +Lastly, you can also add a submit button directly to the form widget: |
| 705 | + |
| 706 | +```dart |
| 707 | +NyForm( |
| 708 | + form: form, |
| 709 | + footer: Button.primary(text: "Submit", submitForm: (form, (data) { |
| 710 | + printInfo(data); |
| 711 | + })), |
| 712 | +) |
| 713 | +``` |
| 714 | + |
| 715 | +Or with another widget: |
| 716 | + |
| 717 | +```dart |
| 718 | +NyForm( |
| 719 | + form: form, |
| 720 | + footer: MaterialButton(onPressed: () { |
| 721 | + form.submit(onSuccess: (data) { |
| 722 | + printInfo(data); |
| 723 | + }); |
| 724 | + }, child: Text("Submit")), |
| 725 | +) |
| 726 | +``` |
| 727 | + |
545 | 728 | <a name="form-styling"></a> |
546 | 729 | <br> |
547 | 730 |
|
|
0 commit comments