Skip to content

Commit ebd8c7d

Browse files
author
Liran Cohen
committed
Fix required checkbox validation.
1 parent a7b7d3c commit ebd8c7d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/Models/CustomField.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(array $attributes = [])
2626
$this->table = config('custom-fields.tables.fields', 'custom_fields');
2727
}
2828

29-
private function fieldValidationRules()
29+
private function fieldValidationRules($required)
3030
{
3131
return [
3232
'text' => [
@@ -44,9 +44,7 @@ private function fieldValidationRules()
4444
'number' => [
4545
'integer',
4646
],
47-
'checkbox' => [
48-
'in:0,1',
49-
],
47+
'checkbox' => $required ? ['accepted','in:0,1'] : ['in:0,1'],
5048
'radio' => [
5149
'string',
5250
'max:255',
@@ -67,7 +65,7 @@ public function responses()
6765

6866
public function getValidationRulesAttribute()
6967
{
70-
$typeRules = $this->fieldValidationRules()[$this->type];
68+
$typeRules = $this->fieldValidationRules($this->required)[$this->type];
7169
array_unshift($typeRules, $this->required ? 'required' : 'nullable');
7270

7371
return $typeRules;

0 commit comments

Comments
 (0)