is possible update data with one request?
I have a component for my plugin in OctoberCMS. I show my repeater's data with a table with an edit and delete button. For example when I clicking the delete button for one item data-request="onDeletePackage" is calling and PHP deletes this item and with ajaxFramework the table refresh.
But I want to get all data and work on them, and for example when to click delete, the item without requesting to the server and when I click save service the repeater fill data.
This is my Code
//php code
public function onDeletePackage()
$packages = Session::get('packages');
if (post('id') !== null)
$id = post('id');
unset($packages[$id]);
Session::put('packages', $packages);
$this->page['packages'] = $packages;
$this->page['service'] = new Service();
% if packages %
<table class="table table-hover dataTable" id="table2">
<tbody>
% set cnt = 1 %
% for key,item in packages %
% if item.is_rejected ==false %
<tr>
<td> cnt </td>
<td> item.receiver_postal_code </td>
<td> item.receiver_address </td>
<td> service.getPostType(item.post_type_id) </td>
<td> service.getPackageType(item.package_type_id) </td>
<td> item.package_number </td>
<td> service.getWeight(item.weight_id) </td>
<td>
<a
href="#"
class="btn btn-default btnEdit"
data-toggle="modal"
data-target="#package-modal"
data-id=" key "
>
<i class="fa fa-edit"></i>
</a>
<a
href="#"
class="btn btn-default"
data-request="onPackageDelete"
data-request-data="id: key "
data-request-update="' __SELF__ ::_packages':'.showPackages'"
>
<i class="fa fa-trash"></i>
</a>
</td>
</tr>
% endif %
% set cnt = cnt + 1 %
% endfor %
</tbody>
</table>
% endif %
<script type="text/javascript">
$(document).ready(function ()
$(".btnEdit").click(function ()
id = $(this).attr('data-id');
$("input[name='package_id']").val(id);
packages= packages;
$("input[name='receiver_postal_code']").val(packages[id].receiver_postal_code);
$("input[name='receiver_address']").val(packages[id].receiver_address);
$("select[name='weight_id']").val(packages[id].weight_id).change();
$("select[name='post_type_id']").val(packages[id].post_type_id).change();
$("select[name='package_type_id']").val(packages[id].package_type_id).change();
$("select[name='insurance_type_id']").val(packages[id].insurance_type_id).change();
$("select[name='distribution_time_id']").val(packages[id].distribution_time_id).change();
$("select[name='special_services_id']").val(packages[id].special_services_id).change();
$("input[name='package_number']").val(packages[id].package_number);
$('#package-modal').find('.modal-title').text('فرم ویرایش بسته');
);
$("#btn-newPack").click(function ()
$('#my-form')[0].reset();
$('span.select2-selection__rendered').text('انتخاب کنید');
$("input[name='package_id']").val("");
$('#package-modal').find('.modal-title').text('فرم ایجاد بسته جدید');
);
);
</script>
octobercms octobercms-plugins
add a comment |
I have a component for my plugin in OctoberCMS. I show my repeater's data with a table with an edit and delete button. For example when I clicking the delete button for one item data-request="onDeletePackage" is calling and PHP deletes this item and with ajaxFramework the table refresh.
But I want to get all data and work on them, and for example when to click delete, the item without requesting to the server and when I click save service the repeater fill data.
This is my Code
//php code
public function onDeletePackage()
$packages = Session::get('packages');
if (post('id') !== null)
$id = post('id');
unset($packages[$id]);
Session::put('packages', $packages);
$this->page['packages'] = $packages;
$this->page['service'] = new Service();
% if packages %
<table class="table table-hover dataTable" id="table2">
<tbody>
% set cnt = 1 %
% for key,item in packages %
% if item.is_rejected ==false %
<tr>
<td> cnt </td>
<td> item.receiver_postal_code </td>
<td> item.receiver_address </td>
<td> service.getPostType(item.post_type_id) </td>
<td> service.getPackageType(item.package_type_id) </td>
<td> item.package_number </td>
<td> service.getWeight(item.weight_id) </td>
<td>
<a
href="#"
class="btn btn-default btnEdit"
data-toggle="modal"
data-target="#package-modal"
data-id=" key "
>
<i class="fa fa-edit"></i>
</a>
<a
href="#"
class="btn btn-default"
data-request="onPackageDelete"
data-request-data="id: key "
data-request-update="' __SELF__ ::_packages':'.showPackages'"
>
<i class="fa fa-trash"></i>
</a>
</td>
</tr>
% endif %
% set cnt = cnt + 1 %
% endfor %
</tbody>
</table>
% endif %
<script type="text/javascript">
$(document).ready(function ()
$(".btnEdit").click(function ()
id = $(this).attr('data-id');
$("input[name='package_id']").val(id);
packages= packages;
$("input[name='receiver_postal_code']").val(packages[id].receiver_postal_code);
$("input[name='receiver_address']").val(packages[id].receiver_address);
$("select[name='weight_id']").val(packages[id].weight_id).change();
$("select[name='post_type_id']").val(packages[id].post_type_id).change();
$("select[name='package_type_id']").val(packages[id].package_type_id).change();
$("select[name='insurance_type_id']").val(packages[id].insurance_type_id).change();
$("select[name='distribution_time_id']").val(packages[id].distribution_time_id).change();
$("select[name='special_services_id']").val(packages[id].special_services_id).change();
$("input[name='package_number']").val(packages[id].package_number);
$('#package-modal').find('.modal-title').text('فرم ویرایش بسته');
);
$("#btn-newPack").click(function ()
$('#my-form')[0].reset();
$('span.select2-selection__rendered').text('انتخاب کنید');
$("input[name='package_id']").val("");
$('#package-modal').find('.modal-title').text('فرم ایجاد بسته جدید');
);
);
</script>
octobercms octobercms-plugins
may be just use repeater data and show table row including with hidden fields [containing single data-set
], up on deletedo not use ajax
justremove element div/row etc containing hidden fields so it removed
so when you click save it will sendonly available hidden fields data
so you get them and save themwith single request
may be.
– Hardik Satasiya
Nov 12 at 13:22
add a comment |
I have a component for my plugin in OctoberCMS. I show my repeater's data with a table with an edit and delete button. For example when I clicking the delete button for one item data-request="onDeletePackage" is calling and PHP deletes this item and with ajaxFramework the table refresh.
But I want to get all data and work on them, and for example when to click delete, the item without requesting to the server and when I click save service the repeater fill data.
This is my Code
//php code
public function onDeletePackage()
$packages = Session::get('packages');
if (post('id') !== null)
$id = post('id');
unset($packages[$id]);
Session::put('packages', $packages);
$this->page['packages'] = $packages;
$this->page['service'] = new Service();
% if packages %
<table class="table table-hover dataTable" id="table2">
<tbody>
% set cnt = 1 %
% for key,item in packages %
% if item.is_rejected ==false %
<tr>
<td> cnt </td>
<td> item.receiver_postal_code </td>
<td> item.receiver_address </td>
<td> service.getPostType(item.post_type_id) </td>
<td> service.getPackageType(item.package_type_id) </td>
<td> item.package_number </td>
<td> service.getWeight(item.weight_id) </td>
<td>
<a
href="#"
class="btn btn-default btnEdit"
data-toggle="modal"
data-target="#package-modal"
data-id=" key "
>
<i class="fa fa-edit"></i>
</a>
<a
href="#"
class="btn btn-default"
data-request="onPackageDelete"
data-request-data="id: key "
data-request-update="' __SELF__ ::_packages':'.showPackages'"
>
<i class="fa fa-trash"></i>
</a>
</td>
</tr>
% endif %
% set cnt = cnt + 1 %
% endfor %
</tbody>
</table>
% endif %
<script type="text/javascript">
$(document).ready(function ()
$(".btnEdit").click(function ()
id = $(this).attr('data-id');
$("input[name='package_id']").val(id);
packages= packages;
$("input[name='receiver_postal_code']").val(packages[id].receiver_postal_code);
$("input[name='receiver_address']").val(packages[id].receiver_address);
$("select[name='weight_id']").val(packages[id].weight_id).change();
$("select[name='post_type_id']").val(packages[id].post_type_id).change();
$("select[name='package_type_id']").val(packages[id].package_type_id).change();
$("select[name='insurance_type_id']").val(packages[id].insurance_type_id).change();
$("select[name='distribution_time_id']").val(packages[id].distribution_time_id).change();
$("select[name='special_services_id']").val(packages[id].special_services_id).change();
$("input[name='package_number']").val(packages[id].package_number);
$('#package-modal').find('.modal-title').text('فرم ویرایش بسته');
);
$("#btn-newPack").click(function ()
$('#my-form')[0].reset();
$('span.select2-selection__rendered').text('انتخاب کنید');
$("input[name='package_id']").val("");
$('#package-modal').find('.modal-title').text('فرم ایجاد بسته جدید');
);
);
</script>
octobercms octobercms-plugins
I have a component for my plugin in OctoberCMS. I show my repeater's data with a table with an edit and delete button. For example when I clicking the delete button for one item data-request="onDeletePackage" is calling and PHP deletes this item and with ajaxFramework the table refresh.
But I want to get all data and work on them, and for example when to click delete, the item without requesting to the server and when I click save service the repeater fill data.
This is my Code
//php code
public function onDeletePackage()
$packages = Session::get('packages');
if (post('id') !== null)
$id = post('id');
unset($packages[$id]);
Session::put('packages', $packages);
$this->page['packages'] = $packages;
$this->page['service'] = new Service();
% if packages %
<table class="table table-hover dataTable" id="table2">
<tbody>
% set cnt = 1 %
% for key,item in packages %
% if item.is_rejected ==false %
<tr>
<td> cnt </td>
<td> item.receiver_postal_code </td>
<td> item.receiver_address </td>
<td> service.getPostType(item.post_type_id) </td>
<td> service.getPackageType(item.package_type_id) </td>
<td> item.package_number </td>
<td> service.getWeight(item.weight_id) </td>
<td>
<a
href="#"
class="btn btn-default btnEdit"
data-toggle="modal"
data-target="#package-modal"
data-id=" key "
>
<i class="fa fa-edit"></i>
</a>
<a
href="#"
class="btn btn-default"
data-request="onPackageDelete"
data-request-data="id: key "
data-request-update="' __SELF__ ::_packages':'.showPackages'"
>
<i class="fa fa-trash"></i>
</a>
</td>
</tr>
% endif %
% set cnt = cnt + 1 %
% endfor %
</tbody>
</table>
% endif %
<script type="text/javascript">
$(document).ready(function ()
$(".btnEdit").click(function ()
id = $(this).attr('data-id');
$("input[name='package_id']").val(id);
packages= packages;
$("input[name='receiver_postal_code']").val(packages[id].receiver_postal_code);
$("input[name='receiver_address']").val(packages[id].receiver_address);
$("select[name='weight_id']").val(packages[id].weight_id).change();
$("select[name='post_type_id']").val(packages[id].post_type_id).change();
$("select[name='package_type_id']").val(packages[id].package_type_id).change();
$("select[name='insurance_type_id']").val(packages[id].insurance_type_id).change();
$("select[name='distribution_time_id']").val(packages[id].distribution_time_id).change();
$("select[name='special_services_id']").val(packages[id].special_services_id).change();
$("input[name='package_number']").val(packages[id].package_number);
$('#package-modal').find('.modal-title').text('فرم ویرایش بسته');
);
$("#btn-newPack").click(function ()
$('#my-form')[0].reset();
$('span.select2-selection__rendered').text('انتخاب کنید');
$("input[name='package_id']").val("");
$('#package-modal').find('.modal-title').text('فرم ایجاد بسته جدید');
);
);
</script>
//php code
public function onDeletePackage()
$packages = Session::get('packages');
if (post('id') !== null)
$id = post('id');
unset($packages[$id]);
Session::put('packages', $packages);
$this->page['packages'] = $packages;
$this->page['service'] = new Service();
% if packages %
<table class="table table-hover dataTable" id="table2">
<tbody>
% set cnt = 1 %
% for key,item in packages %
% if item.is_rejected ==false %
<tr>
<td> cnt </td>
<td> item.receiver_postal_code </td>
<td> item.receiver_address </td>
<td> service.getPostType(item.post_type_id) </td>
<td> service.getPackageType(item.package_type_id) </td>
<td> item.package_number </td>
<td> service.getWeight(item.weight_id) </td>
<td>
<a
href="#"
class="btn btn-default btnEdit"
data-toggle="modal"
data-target="#package-modal"
data-id=" key "
>
<i class="fa fa-edit"></i>
</a>
<a
href="#"
class="btn btn-default"
data-request="onPackageDelete"
data-request-data="id: key "
data-request-update="' __SELF__ ::_packages':'.showPackages'"
>
<i class="fa fa-trash"></i>
</a>
</td>
</tr>
% endif %
% set cnt = cnt + 1 %
% endfor %
</tbody>
</table>
% endif %
<script type="text/javascript">
$(document).ready(function ()
$(".btnEdit").click(function ()
id = $(this).attr('data-id');
$("input[name='package_id']").val(id);
packages= packages;
$("input[name='receiver_postal_code']").val(packages[id].receiver_postal_code);
$("input[name='receiver_address']").val(packages[id].receiver_address);
$("select[name='weight_id']").val(packages[id].weight_id).change();
$("select[name='post_type_id']").val(packages[id].post_type_id).change();
$("select[name='package_type_id']").val(packages[id].package_type_id).change();
$("select[name='insurance_type_id']").val(packages[id].insurance_type_id).change();
$("select[name='distribution_time_id']").val(packages[id].distribution_time_id).change();
$("select[name='special_services_id']").val(packages[id].special_services_id).change();
$("input[name='package_number']").val(packages[id].package_number);
$('#package-modal').find('.modal-title').text('فرم ویرایش بسته');
);
$("#btn-newPack").click(function ()
$('#my-form')[0].reset();
$('span.select2-selection__rendered').text('انتخاب کنید');
$("input[name='package_id']").val("");
$('#package-modal').find('.modal-title').text('فرم ایجاد بسته جدید');
);
);
</script>
//php code
public function onDeletePackage()
$packages = Session::get('packages');
if (post('id') !== null)
$id = post('id');
unset($packages[$id]);
Session::put('packages', $packages);
$this->page['packages'] = $packages;
$this->page['service'] = new Service();
% if packages %
<table class="table table-hover dataTable" id="table2">
<tbody>
% set cnt = 1 %
% for key,item in packages %
% if item.is_rejected ==false %
<tr>
<td> cnt </td>
<td> item.receiver_postal_code </td>
<td> item.receiver_address </td>
<td> service.getPostType(item.post_type_id) </td>
<td> service.getPackageType(item.package_type_id) </td>
<td> item.package_number </td>
<td> service.getWeight(item.weight_id) </td>
<td>
<a
href="#"
class="btn btn-default btnEdit"
data-toggle="modal"
data-target="#package-modal"
data-id=" key "
>
<i class="fa fa-edit"></i>
</a>
<a
href="#"
class="btn btn-default"
data-request="onPackageDelete"
data-request-data="id: key "
data-request-update="' __SELF__ ::_packages':'.showPackages'"
>
<i class="fa fa-trash"></i>
</a>
</td>
</tr>
% endif %
% set cnt = cnt + 1 %
% endfor %
</tbody>
</table>
% endif %
<script type="text/javascript">
$(document).ready(function ()
$(".btnEdit").click(function ()
id = $(this).attr('data-id');
$("input[name='package_id']").val(id);
packages= packages;
$("input[name='receiver_postal_code']").val(packages[id].receiver_postal_code);
$("input[name='receiver_address']").val(packages[id].receiver_address);
$("select[name='weight_id']").val(packages[id].weight_id).change();
$("select[name='post_type_id']").val(packages[id].post_type_id).change();
$("select[name='package_type_id']").val(packages[id].package_type_id).change();
$("select[name='insurance_type_id']").val(packages[id].insurance_type_id).change();
$("select[name='distribution_time_id']").val(packages[id].distribution_time_id).change();
$("select[name='special_services_id']").val(packages[id].special_services_id).change();
$("input[name='package_number']").val(packages[id].package_number);
$('#package-modal').find('.modal-title').text('فرم ویرایش بسته');
);
$("#btn-newPack").click(function ()
$('#my-form')[0].reset();
$('span.select2-selection__rendered').text('انتخاب کنید');
$("input[name='package_id']").val("");
$('#package-modal').find('.modal-title').text('فرم ایجاد بسته جدید');
);
);
</script>
octobercms octobercms-plugins
octobercms octobercms-plugins
asked Nov 11 at 5:34
ehsan
377
377
may be just use repeater data and show table row including with hidden fields [containing single data-set
], up on deletedo not use ajax
justremove element div/row etc containing hidden fields so it removed
so when you click save it will sendonly available hidden fields data
so you get them and save themwith single request
may be.
– Hardik Satasiya
Nov 12 at 13:22
add a comment |
may be just use repeater data and show table row including with hidden fields [containing single data-set
], up on deletedo not use ajax
justremove element div/row etc containing hidden fields so it removed
so when you click save it will sendonly available hidden fields data
so you get them and save themwith single request
may be.
– Hardik Satasiya
Nov 12 at 13:22
may be just use repeater data and show table row including with hidden fields [
containing single data-set
], up on delete do not use ajax
just remove element div/row etc containing hidden fields so it removed
so when you click save it will send only available hidden fields data
so you get them and save them with single request
may be.– Hardik Satasiya
Nov 12 at 13:22
may be just use repeater data and show table row including with hidden fields [
containing single data-set
], up on delete do not use ajax
just remove element div/row etc containing hidden fields so it removed
so when you click save it will send only available hidden fields data
so you get them and save them with single request
may be.– Hardik Satasiya
Nov 12 at 13:22
add a comment |
1 Answer
1
active
oldest
votes
You could change
<tr> to <tr id="pk key ">
then replace
data-request-update="' __SELF__ ::_packages':'.showPackages'"
with
data-request-success="removeRow( key );"
and finally add this to your JS
removeRow function(key)
$('#pk'+ key ).remove();
I think you could also then remove
$this->page['packages'] = $packages;
$this->page['service'] = new Service();
from your PHP onDeletePackage()
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246128%2fis-possible-update-data-with-one-request%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could change
<tr> to <tr id="pk key ">
then replace
data-request-update="' __SELF__ ::_packages':'.showPackages'"
with
data-request-success="removeRow( key );"
and finally add this to your JS
removeRow function(key)
$('#pk'+ key ).remove();
I think you could also then remove
$this->page['packages'] = $packages;
$this->page['service'] = new Service();
from your PHP onDeletePackage()
add a comment |
You could change
<tr> to <tr id="pk key ">
then replace
data-request-update="' __SELF__ ::_packages':'.showPackages'"
with
data-request-success="removeRow( key );"
and finally add this to your JS
removeRow function(key)
$('#pk'+ key ).remove();
I think you could also then remove
$this->page['packages'] = $packages;
$this->page['service'] = new Service();
from your PHP onDeletePackage()
add a comment |
You could change
<tr> to <tr id="pk key ">
then replace
data-request-update="' __SELF__ ::_packages':'.showPackages'"
with
data-request-success="removeRow( key );"
and finally add this to your JS
removeRow function(key)
$('#pk'+ key ).remove();
I think you could also then remove
$this->page['packages'] = $packages;
$this->page['service'] = new Service();
from your PHP onDeletePackage()
You could change
<tr> to <tr id="pk key ">
then replace
data-request-update="' __SELF__ ::_packages':'.showPackages'"
with
data-request-success="removeRow( key );"
and finally add this to your JS
removeRow function(key)
$('#pk'+ key ).remove();
I think you could also then remove
$this->page['packages'] = $packages;
$this->page['service'] = new Service();
from your PHP onDeletePackage()
answered Nov 22 at 2:41
firemankurt
3119
3119
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246128%2fis-possible-update-data-with-one-request%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
may be just use repeater data and show table row including with hidden fields [
containing single data-set
], up on deletedo not use ajax
justremove element div/row etc containing hidden fields so it removed
so when you click save it will sendonly available hidden fields data
so you get them and save themwith single request
may be.– Hardik Satasiya
Nov 12 at 13:22