This repository was archived by the owner on Jan 30, 2020. It is now read-only.
File tree 4 files changed +22
-3
lines changed
4 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,9 @@ public function isValid($context = null)
70
70
}
71
71
72
72
if (! $ hasValue && $ required ) {
73
- $ this ->setErrorMessage ('Value is required ' );
73
+ if ($ this ->errorMessage === null ) {
74
+ $ this ->setErrorMessage ('Value is required ' );
75
+ }
74
76
return false ;
75
77
}
76
78
Original file line number Diff line number Diff line change @@ -124,7 +124,9 @@ public function isValid($context = null)
124
124
}
125
125
126
126
if (! $ hasValue && $ required && ! $ this ->hasFallback ()) {
127
- $ this ->setErrorMessage ('Value is required ' );
127
+ if ($ this ->errorMessage === null ) {
128
+ $ this ->setErrorMessage ('Value is required ' );
129
+ }
128
130
return false ;
129
131
}
130
132
Original file line number Diff line number Diff line change @@ -403,7 +403,9 @@ public function isValid($context = null)
403
403
}
404
404
405
405
if (! $ hasValue && $ required ) {
406
- $ this ->setErrorMessage ('Value is required ' );
406
+ if ($ this ->errorMessage === null ) {
407
+ $ this ->setErrorMessage ('Value is required ' );
408
+ }
407
409
return false ;
408
410
}
409
411
Original file line number Diff line number Diff line change @@ -175,6 +175,19 @@ public function testRequiredWithoutFallbackAndValueNotSetThenFail()
175
175
$ this ->assertEquals (['Value is required ' ], $ input ->getMessages (), 'getMessages() value not match ' );
176
176
}
177
177
178
+ public function testRequiredWithoutFallbackAndValueNotSetThenFailWithCustomErrorMessage ()
179
+ {
180
+ $ input = $ this ->input ;
181
+ $ input ->setRequired (true );
182
+ $ input ->setErrorMessage ('fooErrorMessage ' );
183
+
184
+ $ this ->assertFalse (
185
+ $ input ->isValid (),
186
+ 'isValid() should be return always false when no fallback value, is required, and not data is set. '
187
+ );
188
+ $ this ->assertEquals (['fooErrorMessage ' ], $ input ->getMessages (), 'getMessages() value not match ' );
189
+ }
190
+
178
191
public function testNotRequiredWithoutFallbackAndValueNotSetThenIsValid ()
179
192
{
180
193
$ input = $ this ->input ;
You can’t perform that action at this time.
0 commit comments