new validator for radio buttons
This commit is contained in:
parent
9b40c9788f
commit
5cf1a6c300
3 changed files with 13 additions and 0 deletions
|
@ -103,6 +103,10 @@ class CustomFieldset extends Model
|
||||||
if ($field->element == 'checkbox') {
|
if ($field->element == 'checkbox') {
|
||||||
$rules[$field->db_column_name()][] = 'checkboxes';
|
$rules[$field->db_column_name()][] = 'checkboxes';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($field->element == 'radio') {
|
||||||
|
$rules[$field->db_column_name()][] = 'radio_buttons';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
|
|
|
@ -322,6 +322,14 @@ class ValidationServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Validates that a radio button option exists
|
||||||
|
Validator::extend('radio_buttons', function ($attribute, $value) {
|
||||||
|
$field = CustomField::where('db_column', $attribute)->first();
|
||||||
|
$options = $field->formatFieldValuesAsArray();
|
||||||
|
|
||||||
|
return in_array($value, $options);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -106,6 +106,7 @@ return [
|
||||||
'numeric' => 'Value cannot be negative'
|
'numeric' => 'Value cannot be negative'
|
||||||
],
|
],
|
||||||
'checkboxes' => ':attribute contains invalid options.',
|
'checkboxes' => ':attribute contains invalid options.',
|
||||||
|
'radio_buttons' => ':attribute is invalid.',
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Reference in a new issue