|
4 | 4 | <h3 class="box-title">{{ trans('backpack::crud.add_a_new') }} {{ $crud->entity_name }}</h3> |
5 | 5 | @endsection |
6 | 6 |
|
| 7 | +@php |
| 8 | + $requestData = []; |
| 9 | +
|
| 10 | + foreach ($request->input() as $key => $item) { |
| 11 | + $requestData[] = [ |
| 12 | + 'name' => $key, |
| 13 | + 'value' => $item, |
| 14 | + ]; |
| 15 | + } |
| 16 | +@endphp |
| 17 | + |
7 | 18 | @section('content') |
8 | 19 | <div class="row"> |
9 | 20 | <div class="col-md-10 col-md-offset-1"> |
|
28 | 39 | $("#create_{{ $entity }}").submit(function (e) { |
29 | 40 | e.preventDefault(); // avoid to execute the actual submit of the form. |
30 | 41 |
|
| 42 | + var requestData = <?php echo json_encode($requestData); ?>; |
| 43 | +
|
31 | 44 | $.ajax({ |
32 | 45 | type: "PUT", |
33 | | - url: "/{{ ltrim($crud->route . '/ajax', '/') }}", |
34 | | - data: $("#create_{{ $entity }}").serialize(), // serializes the form's elements. |
35 | | - success: function (data) { |
36 | | - new PNotify({ |
37 | | - type: "success", |
38 | | - title: "{{ trans('backpack::base.success') }}", |
39 | | - text: "{{ trans('backpack::crud.insert_success') }}" |
40 | | - }); |
| 46 | + url: "/{{ ltrim($crud->route . '/ajax', '/') }}", |
| 47 | + data |
| 48 | + : |
| 49 | + $("#create_{{ $entity }}").serialize() + '&' + $.param(requestData), // serializes the form's elements. |
| 50 | + success |
| 51 | + : |
| 52 | +
|
| 53 | + function (data) { |
| 54 | + new PNotify({ |
| 55 | + type: "success", |
| 56 | + title: "{{ trans('backpack::base.success') }}", |
| 57 | + text: "{{ trans('backpack::crud.insert_success') }}" |
| 58 | + }); |
41 | 59 |
|
42 | | - $("#{{ $entity }}_create_modal").modal('hide'); |
| 60 | + $("#{{ $entity }}_create_modal").modal('hide'); |
43 | 61 |
|
44 | | - // provide auto-fill |
| 62 | + // provide auto-fill |
45 | 63 |
|
46 | | - if ($("#select2_ajax_{{ $field_name }}").length) { |
47 | | - searchfield = $("#select2_ajax_{{ $field_name }}") |
| 64 | + if ($("#select2_ajax_{{ $request->input('field_name') }}").length) { |
| 65 | + searchfield = $("#select2_ajax_{{ $request->input('field_name') }}") |
48 | 66 | } else { |
49 | | - searchfield = $("#select2_ajax_multiple_{{ $field_name }}") |
| 67 | + searchfield = $("#select2_ajax_multiple_{{ $request->input('field_name') }}") |
50 | 68 | } |
51 | 69 |
|
52 | 70 | searchfield.select2('open'); |
|
55 | 73 | // Dropdown = single, Selection = multiple |
56 | 74 | var search = searchfield.data('select2').dropdown.$search || searchfield.data('select2').selection.$search; |
57 | 75 | // This is undocumented and may change in the future |
58 | | - var userInput = $("#create_{{ $entity }} [name='{{ $attribute }}']").serializeArray(); |
| 76 | + var userInput = $("#create_{{ $entity }} [name='{{ $request->input('attribute') }}']").serializeArray(); |
59 | 77 |
|
60 | 78 | search.val(userInput[0]['value']); |
61 | 79 | search.trigger('input'); |
|
0 commit comments