@@ -486,7 +486,7 @@ def page4
486
486
487
487
end
488
488
489
- describe "Example 6 - Async submit update request with success, which does not rest the input fields" do
489
+ describe "Example 6 - Async submit update request with success, which does not reset the input fields" do
490
490
# https://github.com/basemate/matestack-ui-core/issues/304
491
491
492
492
# This example uses the `TestModel` with attributes `title` and `description`
@@ -575,6 +575,130 @@ def test_model_params
575
575
end
576
576
end
577
577
578
+ describe "Example 6.1 - Async submit with success configured to reset the input fields" do
579
+ # https://github.com/matestack/matestack-ui-core/pull/314#discussion_r362826471
580
+
581
+ before do
582
+ class Pages ::SearchPage < Matestack ::Ui ::Page
583
+ def response
584
+ components {
585
+ form form_config , :include do
586
+ form_input id : 'query' , key : :query , type : :text
587
+ form_submit { button text : "Search" }
588
+ end
589
+ async show_on : "form_has_errors" , hide_after : 5000 do
590
+ plain "Form has errors"
591
+ end
592
+ async show_on : "submission_successful" , hide_after : 5000 do
593
+ plain "Submission successful"
594
+ end
595
+ }
596
+ end
597
+
598
+ private
599
+
600
+ def form_config
601
+ {
602
+ for : :search ,
603
+ method : :get ,
604
+ path : "#" ,
605
+ success : { emit : "submission_successful" , reset : true } ,
606
+ failure : { emit : "form_has_errors" }
607
+ }
608
+ end
609
+ end
610
+
611
+ class SearchesController < ApplicationController
612
+ include Matestack ::Ui ::Core ::ApplicationHelper
613
+
614
+ def index
615
+ responder_for Pages ::SearchPage
616
+ end
617
+ end
618
+
619
+ Rails . application . routes . draw do
620
+ get 'search' , to : 'searches#index'
621
+ end
622
+ end
623
+
624
+ after do
625
+ Rails . application . reload_routes!
626
+ end
627
+
628
+ specify do
629
+ visit "/search"
630
+ expect ( find_field ( :query ) . value ) . to eq ""
631
+
632
+ fill_in :query , with : "Bar"
633
+ click_on "Search"
634
+
635
+ expect ( page ) . to have_text "Submission successful"
636
+ expect ( find_field ( :query ) . value ) . to eq ""
637
+ end
638
+ end
639
+
640
+ describe "Example 6.2 - Async submit with success configured not to reset the input fields" do
641
+ # https://github.com/matestack/matestack-ui-core/pull/314#discussion_r362826471
642
+
643
+ before do
644
+ class Pages ::SearchPage < Matestack ::Ui ::Page
645
+ def response
646
+ components {
647
+ form form_config , :include do
648
+ form_input id : 'query' , key : :query , type : :text
649
+ form_submit { button text : "Search" }
650
+ end
651
+ async show_on : "form_has_errors" , hide_after : 5000 do
652
+ plain "Form has errors"
653
+ end
654
+ async show_on : "submission_successful" , hide_after : 5000 do
655
+ plain "Submission successful"
656
+ end
657
+ }
658
+ end
659
+
660
+ private
661
+
662
+ def form_config
663
+ {
664
+ for : :search ,
665
+ method : :get ,
666
+ path : "#" ,
667
+ success : { emit : "submission_successful" , reset : false } ,
668
+ failure : { emit : "form_has_errors" }
669
+ }
670
+ end
671
+ end
672
+
673
+ class SearchesController < ApplicationController
674
+ include Matestack ::Ui ::Core ::ApplicationHelper
675
+
676
+ def index
677
+ responder_for Pages ::SearchPage
678
+ end
679
+ end
680
+
681
+ Rails . application . routes . draw do
682
+ get 'search' , to : 'searches#index'
683
+ end
684
+ end
685
+
686
+ after do
687
+ Rails . application . reload_routes!
688
+ end
689
+
690
+ specify do
691
+ visit "/search"
692
+ expect ( find_field ( :query ) . value ) . to eq ""
693
+
694
+ fill_in :query , with : "Bar"
695
+ click_on "Search"
696
+
697
+ expect ( page ) . to have_text "Submission successful"
698
+ expect ( find_field ( :query ) . value ) . to eq "Bar"
699
+ end
700
+ end
701
+
578
702
describe "Form Input Component" do
579
703
580
704
it "Example 1 - Supports 'text', 'password', 'number', 'email', 'textarea' type" do
0 commit comments