front side validations
parent
0dfaea5949
commit
5a85950b85
|
@ -38,8 +38,22 @@ function ManageCoursePage({ courses, authors, actions, history, ...props }) {
|
|||
}));
|
||||
}
|
||||
|
||||
function formIsValid() {
|
||||
const { title, authorId, category } = course;
|
||||
const errors = {};
|
||||
|
||||
if (!title) errors.title = "Title is required.";
|
||||
if (!authorId) errors.author = "Author is required";
|
||||
if (!category) errors.category = "Category is required";
|
||||
|
||||
setErrors(errors);
|
||||
// Form is valid if the errors object still has no properties
|
||||
return Object.keys(errors).length === 0;
|
||||
}
|
||||
|
||||
function handleSave(event) {
|
||||
event.preventDefault();
|
||||
if (!formIsValid()) return;
|
||||
setSaving(true);
|
||||
actions
|
||||
.saveCourse(course)
|
||||
|
|
Loading…
Reference in New Issue