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) {
|
function handleSave(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
if (!formIsValid()) return;
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
actions
|
actions
|
||||||
.saveCourse(course)
|
.saveCourse(course)
|
||||||
|
|
Loading…
Reference in New Issue