Reputation: 705
I have tried to make the data input form but when an empty input form can still be saved when in press save and how when the input is empty then it will not be save.
this is my form code: 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();
}
});
});
Upvotes: 0
Views: 152
Reputation: 319
form_text_arr = {'text': jQuery("form[name='put_ad_form']").serializeArray()};
after you need check each value:
var reg=new RegExp(/^[A-Za-z0-9+*-]{1,10}$/);
if(reg.test(text.val)){
.......
}
or
if(text.val == ''){
alert('please input text');
}
Upvotes: 0
Reputation: 4474
var form = $("#form_news_item");
if(form=="")
{
alert("Please fill field");
}
else
{
$.ajax({
type: "POST",
contentType: "application/json",
url: BASE_URL + "setting/news",
data: JSON.stringify(json),
success: function(response) {
console.log(response);
resetForm();
reloadGrid();
}
}
Upvotes: 1