Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form data in webix UI modal

I'm using Webix UI modal, this is how i use it:

this.add = function () {
scrollArea.css("overflow", "hidden");
$.ajax({
	type: "GET",
	url: "/detail/create",
	success: function (form) {
		webix.message.keyboard = false;
		webix.modalbox({
			title: "New detail",
			buttons: ["Accept", "Decline"],
			text: form,
			width: 400,
			callback: function (result) {
				switch (result) {
					case "0":
						addDetail();
						break;
					case "1":
						break;
				}
				scrollArea.css("overflow", "auto");
			}
		});
	}
});
function addDetail() {
	$.ajaxSetup({
		headers: {
			'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		}
	});
	$.ajax({
		type: "POST",
		url: "/detail/store",
		data: $('#detail_add').serialize(),
		contentType: "JSON",
		processData: false,
		success: function () {
		}
	});
}
};


And form's HTML:
<form action="" id="detail_add" method="post">
<input type="text" name="name" placeholder="Name">
<input type="text" name="article" placeholder="Article">
<input type="hidden" name="location_id" placeholder="1">
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
</form>

When i click Accept in modal, my JSON is empty. How can i fix it? I was trying to get input's value by console.log, but it's empty too.

like image 375
Detryer Avatar asked Jan 31 '17 11:01

Detryer


1 Answers

It's not an answer in general but the example code is not applicable to resolve something because:

  • We don't know what is scrollArea object
  • You try to implement code that is depending on successful script response we don't have
  • We don't have a button with an action to start your code

Here is the code slightly changed to work and to demonstrate your case:

I'm using Webix UI modal, this is how i use it:

scrollArea = $(window.document);
this.add = function() {

  //scrollArea.css("overflow", "hidden");

  $.ajax({
    type: "GET",
    url: "/detail/create",
    beforeSend: function(form) {
      webix.message.keyboard = false;
      webix.modalbox({
        title: "New detail",
        buttons: ["Accept", "Decline"],
        text: form,
        width: 400,
        callback: function(result) {
          switch (result) {
            case "0":
              addDetail();
              break;
            case "1":
              break;
          }
          scrollArea.css("overflow", "auto");
        }
      });
    }
  });

  function addDetail() {
    $.ajaxSetup({
      headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
      }
    });

    $.ajax({
      type: "POST",
      url: "/detail/store",
      data: $('#detail_add').serialize(),
      contentType: "JSON",
      processData: false,
      success: function() {}
    });
  }
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<link rel="stylesheet" href="http://cdn.webix.com/edge/webix.css" type="text/css">
<script src="http://cdn.webix.com/edge/webix.js" type="text/javascript"></script>

<form action="" id="detail_add" method="post">
  <input type="text" name="name" placeholder="Name">
  <input type="text" name="article" placeholder="Article">
  <input type="hidden" name="location_id" placeholder="1">
  <input type="hidden" name="_token" value="{{ csrf_token() }}" />
  <button onClick="add()">Add</button>
</form>

When i click Accept in modal, my JSON is empty. How can i fix it? I was trying to get input's value by console.log, but it's empty too.

like image 153
Daniel Avatar answered Oct 15 '22 10:10

Daniel