0

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();
    }
  });
});
2
  • What do you mean by "it will not be save"? Are you getting a specific error message? Is there no error message but the data does not get saved? Is the data being saved in a malformed format? Commented Jul 23, 2016 at 5:14
  • if input empty I want can not be saved, but in my problem an empty input form can still be saved Commented Jul 23, 2016 at 5:24

2 Answers 2

1
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();
   }
}
Sign up to request clarification or add additional context in comments.

Comments

0
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');
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.