alertify.confirm change value on text

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
FelipeRau12
User
Posts: 45

alertify.confirm change value on text

Post by FelipeRau12 »

Hello,

I have a situation: In an edit screen when the value of a value field is changed, I need to ask the user if they want to change the values ​​of other records in the same table.

I did this part in javascript
$("#x_vldespesa").on('change', function(e){
alertify.confirm('Deseja atualizar os valores nas despesas gerados neste intervalo, que ainda estão abertos?', function (ok) { $.post(ew_CurrentPage(), { "myajax": 1, "token": EW_TOKEN, "value": "1"}); }).set('title', 'Confirmação');
});

and in row_updated has a part in php to run a mysql sp that does the updates.
In page_render archive edit.php
if (@$POST["myajax"] == 1 && @$POST["value"] != "") { // Check if it is your custom Ajax and if the query value is present
$SESSION["inorigemgeradod"] = $POST["value"];
$this->Page_Terminate(); // Terminate the page
} else {
$_SESSION["inorigemgeradod"] = "0";
}

function Row_Updated

if ($SESSION["inorigemgeradod"] == "1") {
if ($rsold['cddespesa'] <> "") {$cddespesa = $rsold['cddespesa'];} else {$cddespesa = $rsnew['cddespesa'];}
unset($
SESSION["inorigemgeradod"]);
ew_Execute("call fin06_spatualizaintervalo(1,".$inorigemgerada.",".$cddespesa."); ");
}

My problem is that the question that is asked to the user has 2 buttons if you click ok but does not click. I should not change anything but I can not use alertify.confirm correctly. What is wrong?


kirondedshem
User
Posts: 642

Post by kirondedshem »

  1. ensure that the ajax call works you can put console logs a various points to be sure that it paases the test
    2.I think you should put the php that is supposed to execute the ajax post into page_load instead since it is called before all else. ALos note that if you are using a modal edit form, you should put it in page_load of list page as well since its the current page then.

I dont know the various use cases by which the user changes the value, But since the actual update is done only during row_updated(basically after the form is submitted), i feel its tiresome assuming the user changes the value like 10 times before sumbitting you will have to popup that dialog 10 times just to save a sseission, whose value can still be available during row_updated if it was a field on the form as well.

SO ALternatively I would approach it more smoothly like this.

  1. add a custom field eg "change_all_records" (this means it can appear on edit form and its value is still available in both orw_updating and row_updated events)
  2. Set it as a checkbox, or drop down and provide a user defined list including yes and no as possible options(here I can even add as many as possible). This is the equivalent of the button you would put on the alertify dialog.
  3. Make it mandatory such that a user has to select an option.
  4. then impliment logic row_updated like

//assuming it is drop down with options Yes and No
if ($rsnew['change_all_records'] == "Yes") {
if ($rsold['cddespesa'] <> "") {$cddespesa = $rsold['cddespesa'];} else {$cddespesa = $rsnew['cddespesa'];}
unset($_SESSION["inorigemgeradod"]);
ew_Execute("call fin06_spatualizaintervalo(1,".$inorigemgerada.",".$cddespesa."); ");
}


FelipeRau12
User
Posts: 45

Post by FelipeRau12 »

Hello,

Strange had previously done test where I had placed Custom Field to finish if the user had changed or not the values ​​the only one different was a text field and the value was changed via javascript. When I tried to fetch in Row_updated the field appeared only worthless.

Now putting the Radio Box option worked.

I solved my problem so:

script client
function activealter() {
var cred = document.getElementsByName("x_change_all_records");


for(var i = 0; i < cred.length; i++){
if(cred[i].value == 1){
cred[i].checked = true;
}
}
}

if ($("#x_inorigemgerada").val() > 0) {
$("#x_vldespesa").on('change', function(e){

 // alertify.confirm('Deseja atualizar os valores nas despesas gerados neste intervalo, que ainda estão abertos?', function (ok) {<?php $_SESSION["inorigemgeradod"] = "1";?>}).set('title', 'Confirmação');
   alertify.confirm('Deseja atualizar os valores nas despesas gerados neste intervalo, que ainda estão abertos?', function (ok) { activealter(); }).set('title', 'Confirmação');    
});

in Row_Updated:

// print_r($rsnew);
// die();
// Calcular os valores de saldo - Felipe Rau - 25/05/2017
if ($rsold['vldespesa'] <> $rsnew['vldespesa']) {
ew_Execute("call fin05_spcalculavalorestitulos(0,". $rsold['cddespesa'].");");
if ($rsold['inorigemgerada'] <> "") {$inorigemgerada = $rsold['inorigemgerada'];} else {$inorigemgerada = $rsnew['inorigemgerada'];}
if ($inorigemgerada > 0 and $rsnew['change_all_records'] == "1") {
if ($rsold['cddespesa'] <> "") {$cddespesa = $rsold['cddespesa'];} else {$cddespesa = $rsnew['cddespesa'];}
unset($_SESSION["inorigemgeradod"]);
ew_Execute("call fin06_spatualizaintervalo(1,".$inorigemgerada.",".$cddespesa."); ");
}
}

Thanks kirondedshem

now it works!


Post Reply