diff --git a/client/src/app/admin/panel/users/admin-panel-custom-field-form.js b/client/src/app/admin/panel/users/admin-panel-custom-field-form.js index f4f7275e..a95eef0b 100644 --- a/client/src/app/admin/panel/users/admin-panel-custom-field-form.js +++ b/client/src/app/admin/panel/users/admin-panel-custom-field-form.js @@ -21,7 +21,10 @@ class AdminPanelCustomFieldForm extends React.Component { state = { loading: false, error: null, - addForm: {}, + addForm: { + name: "", + description: "" + }, addFormOptions: [], }; diff --git a/server/controllers/system/add-custom-field.php b/server/controllers/system/add-custom-field.php index 1e584d1f..2743e5e9 100644 --- a/server/controllers/system/add-custom-field.php +++ b/server/controllers/system/add-custom-field.php @@ -1,5 +1,6 @@ ERRORS::INVALID_NAME ], 'description' => [ - 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_DESCRIPTION, LengthConfig::MAX_LENGTH_DESCRIPTION), + 'validation' => DataValidator::length(LengthConfig::MIN_LENGTH_DESCRIPTION, LengthConfig::MAX_LENGTH_DESCRIPTION), 'error' => ERRORS::INVALID_DESCRIPTION ], 'type' => [ @@ -53,7 +54,7 @@ class AddCustomFieldController extends Controller { ], 'options' => [ 'validation' => DataValidator::oneOf( - DataValidator::json(), + DataValidator::ValidOptions(), DataValidator::nullType() ), 'error' => ERRORS::INVALID_CUSTOM_FIELD_OPTIONS @@ -68,8 +69,9 @@ class AddCustomFieldController extends Controller { $description = Controller::request('description', true); $options = Controller::request('options'); - if(!Customfield::getDataStore($name, 'name')->isNull()) + if(!Customfield::getDataStore($name, 'name')->isNull()) { throw new Exception(ERRORS::CUSTOM_FIELD_ALREADY_EXISTS); + } $customField = new Customfield(); $customField->setProperties([ diff --git a/server/data/length-config.php b/server/data/length-config.php index 0b54fc64..31872ceb 100644 --- a/server/data/length-config.php +++ b/server/data/length-config.php @@ -11,7 +11,7 @@ class LengthConfig { const MIN_LENGTH_PASSWORD = 6; const MAX_LENGTH_PASSWORD = 200; - const MIN_LENGTH_DESCRIPTION = 2; + const MIN_LENGTH_DESCRIPTION = 0; const MAX_LENGTH_DESCRIPTION = 100; const MIN_LENGTH_TOKEN = 1; diff --git a/server/libs/validations/validOptions.php b/server/libs/validations/validOptions.php new file mode 100644 index 00000000..46814f41 --- /dev/null +++ b/server/libs/validations/validOptions.php @@ -0,0 +1,28 @@ +