Commit 863c5c5 1 parent d9fcda0 commit 863c5c5 Copy full SHA for 863c5c5
File tree 2 files changed +68
-1
lines changed
2 files changed +68
-1
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,10 @@ public function rules()
87
87
$ data [$ field ['id ' ]] = isset ($ tmpop ['name ' ]) ? $ tmpop ['name ' ] : $ data [$ field ['id ' ]];
88
88
}
89
89
}
90
- if (FormLogicPropertyResolver::isRequired ($ property , $ data ) && (!isset ($ property ['hidden ' ]) || !$ property ['hidden ' ])) {
90
+ if (
91
+ FormLogicPropertyResolver::isRequired ($ property , $ data ) &&
92
+ !FormLogicPropertyResolver::isHidden ($ property , $ data )
93
+ ) {
91
94
$ rules [] = 'required ' ;
92
95
93
96
if ($ property ['type ' ] == 'checkbox ' ) {
Original file line number Diff line number Diff line change 543
543
'message ' => $ validationMessage ,
544
544
]);
545
545
});
546
+
547
+ it ('skips validation for fields hidden by logic conditions ' , function () {
548
+ $ user = $ this ->actingAsUser ();
549
+ $ workspace = $ this ->createUserWorkspace ($ user );
550
+ $ form = $ this ->createForm ($ user , $ workspace , [
551
+ 'properties ' => [
552
+ [
553
+ 'id ' => 'title ' ,
554
+ 'name ' => 'Name ' ,
555
+ 'type ' => 'title ' ,
556
+ 'hidden ' => false ,
557
+ 'required ' => true ,
558
+ 'logic ' => [
559
+ 'conditions ' => [
560
+ 'operatorIdentifier ' => 'and ' ,
561
+ 'children ' => [
562
+ [
563
+ 'identifier ' => 'email ' ,
564
+ 'value ' => [
565
+ 'operator ' => 'is_empty ' ,
566
+ 'property_meta ' => [
567
+ 'id ' => 'email_field ' ,
568
+ 'type ' => 'email ' ,
569
+ ],
570
+ 'value ' => true ,
571
+ ],
572
+ ],
573
+ ],
574
+ ],
575
+ 'actions ' => ['hide-block ' ],
576
+ ],
577
+ ],
578
+ [
579
+ 'id ' => 'email_field ' ,
580
+ 'name ' => 'Email ' ,
581
+ 'type ' => 'email ' ,
582
+ 'hidden ' => false ,
583
+ 'required ' => false ,
584
+ ],
585
+ ],
586
+ ]);
587
+
588
+ // Test when field should be hidden (email is empty)
589
+ $ formData = ['email_field ' => '' ]; // Empty email
590
+ $ this ->postJson (route ('forms.answer ' , $ form ->slug ), $ formData )
591
+ ->assertSuccessful ()
592
+ ->assertJson ([
593
+ 'type ' => 'success ' ,
594
+ 'message ' => 'Form submission saved. ' ,
595
+ ]);
596
+
597
+ // Test when field should be visible (email is not empty)
598
+ $ formData = ['email_field ' => 'test@example.com ' ];
599
+ $ this ->postJson (route ('forms.answer ' , $ form ->slug ), $ formData )
600
+ ->assertStatus (422 )
601
+ ->assertJson ([
602
+ 'message ' => 'The Name field is required. ' ,
603
+ 'errors ' => [
604
+ 'title ' => [
605
+ 'The Name field is required. ' ,
606
+ ],
607
+ ],
608
+ ]);
609
+ });
You can’t perform that action at this time.
0 commit comments