I am attempting to create a data input form, but I have run into an issue. Even when the form is empty, it can still be saved when the save button is pressed. How can I prevent saving if the input fields are empty?
Here is the code for my form: https://jsfiddle.net/bubyj5xj/
$(".btn_save_news_item").button().click(function() {
var form = $("#form_news_item");
var json = ConvertFormToJSON(form);
$.ajax({
type: "POST",
contentType: "application/json",
url: BASE_URL + "setting/news",
data: JSON.stringify(json),
success: function(response) {
console.log(response);
resetForm();
reloadGrid();
}
});
});