mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
new validator for radio buttons
This commit is contained in:
parent
9b40c9788f
commit
5cf1a6c300
|
@ -103,6 +103,10 @@ class CustomFieldset extends Model
|
|||
if ($field->element == 'checkbox') {
|
||||
$rules[$field->db_column_name()][] = 'checkboxes';
|
||||
}
|
||||
|
||||
if ($field->element == 'radio') {
|
||||
$rules[$field->db_column_name()][] = 'radio_buttons';
|
||||
}
|
||||
}
|
||||
|
||||
return $rules;
|
||||
|
|
|
@ -322,6 +322,14 @@ class ValidationServiceProvider extends ServiceProvider
|
|||
|
||||
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'
|
||||
],
|
||||
'checkboxes' => ':attribute contains invalid options.',
|
||||
'radio_buttons' => ':attribute is invalid.',
|
||||
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue