This topic is locked
[SOLVED]

 Toggle checkbox in one row in list page

12/19/2017 1:58:55 PM
PHPRunner General questions
W
wedi author

Hallo,
is it possible to uncheck a checkbox when another checkbox in the same row (in list page) was checked and i need this without save and reload the list page?
I would be very happy if anybody has a solution.
Thanks

wedi

admin 12/20/2017

Can you post a screenshot that explains what checkboxes do you mean?

W
wedi author 12/21/2017

Hello Sergey,
You may call me a fool, but where can i upload a screenshot. I don't find the Button [Choose File] which is named in help for "Posting" (subtitle Attachements - Default Uploader)
I very much apologize my unhandiness
wedi

admin 12/22/2017

Upload your screenshot to any image sharing website like imgur.com and post a link here.

W
wedi author 12/22/2017

Thanks for your help.
Here is the screenshot:


In each column with a checkbox in "view as - custom" i use the following code from this blog-entry (https://xlinesoft.com/blog/2015/10/30/excel-like-grid-in-phprunner-applications/)
$field="Vx"; // (Vx --> x=1 to 4):

$keyField="id";
$value = "<input data-fieldname='".$field."' type=checkbox data-editid='".$data[$keyField]."' class='chAutoUpdate' ";

if ($data[$field])

$value.="checked ";

$value.=">";
The code in "Javascript onload" (also from the blog-entry) update the 4 columns when one of them is checked by mouseclick. The one which was clicked "to checked" and the other columns "to unchecked".

But that changes only the value of the columns in the table and not in the list page (except the column i've clicked). And (as i mentioned in my first post) i don't want to reload the list-page after every mouseclick, because it takes to much time.
Sincerely

wedi

W
wedi author 12/24/2017

I've tried another approach to my problem. Now i use one (integer) column (Value 1 to 4) instead of 4 (bit) columns (see my previous post)


To get this i use the following code in "view as" to the column "Werte":



$value="<input class='chAutoUpdate' type=radio name='vx".$data[$keyField]."' value='1' data-fieldname='v1' data-editid='".$data[$keyField]."' ";

if ($data[$field]==1) $value.="checked ";

$value.=">&nbsp1&nbsp&nbsp&nbsp&nbsp&nbsp";

$value.="<input class='chAutoUpdate' type=radio name='vx".$data[$keyField]."' value='2' data-fieldname='v2' data-editid='".$data[$keyField]."' ";

if ($data[$field]==2) $value.="checked ";

$value.=">&nbsp5&nbsp&nbsp&nbsp&nbsp&nbsp";

$value.="<input class='chAutoUpdate' type=radio name='vx".$data[$keyField]."' value='3' data-fieldname='v3' data-editid='".$data[$keyField]."' ";

if ($data[$field]==3) $value.="checked ";

$value.=">&nbsp8&nbsp&nbsp&nbsp&nbsp&nbsp";

$value.="<input class='chAutoUpdate' type=radio name='vx".$data[$keyField]."' value='4' data-fieldname='v4' data-editid='".$data[$keyField]."' ";

if ($data[$field]==4) $value.="checked ";

$value.=">&nbsp>10&nbsp&nbsp&nbsp&nbsp&nbsp";


As you can see in the screenshot, the list page is filled with the correct values from the tablecolumn.
For update the value, when changing the radio-button in a row, i use the following code in "Javascript onload event":

The name of the tablecolumn is "Bewertung_value"



var fields = ["v1", "v2", "v3", "v4"];

var ctrl;

var elem;

$(document).ready(function() {

$('.chAutoUpdate').change(function() {

var id = $(this).attr("data-editid");

var field=$(this).attr("data-fieldname");

var val="";

elem = $(this);
var data = {

id: 1,

editType: "inline",

a: "edited",

editid1: id

};

// aktuellen wert setzen

for (i = 0; i < 5; i++) {

if (fields[i] == field) {

var num = (i + 1);

data["value_Bewertung_value_1"]=num;

data["type_Bewertung_value_1"]="radio";

}

}
// save data



$.ajax({

type: "POST",

url: "dbo_T_PraktikumBewertungTest_edit.php?submit=1",

data: data

}).done( function(jsondata) {

var decoded = $('<div/>').html(jsondata).text();

response = jQuery.parseJSON( decoded );

if (response["success"]==false) {

$("<div class=rnr-error/>").insertAfter(elem).html(response["message"]);

}

});

});



});


But the update doesn't work.
So here my questions:

What is wrong in this code?

How can i get the value (1 to 4) from the "radiogroup"?

And how must i address the columntable for the ajax json data?
Thanks for your assistance.

wedi

W
wedi author 1/7/2018

Hello,
After some experimentation i found a solution for this problem by myself.
As i described, the value i want to save in table is bewertung_value which is shown as type=radio and i think this is the problem when saving the value.

What i've done is to modify my query and now i have an additional field named vx with the value of bewertung_value. This column is hidden (like the id-column), so nobody can see this additional column on List page.
In List page - Javascript onload event, i changed the code like this:


// check which radiobutton was clicked

for (i = 0; i < 4; i++) {

if (fields[i] == field) {

var num = (i + 1);

data["value_vx_1"]=num;

}

}
// save data



$.ajax({

type: "POST",

url: "dbo_v_praktikumBewertung_edit.php?submit=1",

data: data

}).done(function(jsondata) {

var decoded = $('<div/>').html(jsondata).text();

response = jQuery.parseJSON( decoded );

});


Thanks for your help.