I’ve a little problem. In my solution there is a form, which has a table view on it. In this, there a several columns whose dataprovider is directly a column of my table or a relation into another one. They all are not editable. Everything works fine…
Now I need another column in my table view, with a editable checkbox in it. I was looking for a solution in this “Servoy Talk” an found one. I added a non restored calculation to my table with following code:
function va_kontakt()
{
return;
}
I gave this dataprovider-calculation to the checkbox and when I run following code in the “onAction”-event of the checkbox, everything is fine:
function onAction(event) {
var curIndex = foundset.getSelectedIndex()
for (var i = 1; i <= foundset.getSize(); i++) {
if (i != m_curIndex) {
foundset.getRecord(i).va_kontakt = false
}
}
}
After this event, only the current selected checkbox ist checked and the other are not, that’s what I like.
On another case, I do somthing like this:
function onSelect(param_persnr) {
for (var i = 1; i <= foundset.getSize(); i++) {
if (foundset.getRecord(i).persnr == param_persnr) {
foundset.getRecord(i).va_kontakt = true
} else {
foundset.getRecord(i).va_kontakt = false
}
}
}
But now, all checkboxes in the table view are unselected. I debugged my code and the if-clause occured exactly one time during the for-turn, but never a checkbox is checked.
ich:
I gave this dataprovider-calculation to the checkbox and when I run following code in the “onAction”-event of the checkbox, everything is fine:
function onAction(event) {
var curIndex = foundset.getSelectedIndex()
for (var i = 1; i <= foundset.getSize(); i++) {
if (i != m_curIndex) {
foundset.getRecord(i).va_kontakt = 0
}
}
}
After this event, only the current selected checkbox ist checked and the other are not, that's what I like.
You don’t need to loop to get to the selected record, when you click on a record it is already selected. Also the fields of the current record can be accessed directly in the code, you don’t have to do getRecord first. So this code will do exactly the same:
function onAction(event) {
va_kontakt = 0;
}
But I really don’t understand what you are trying to do here, you want to show a checkbox that can only be unchecked?
In your second function you are setting the va_kontakt to 1 for one record and to 0 for the rest?
Why not just create a global variable containing the param_persnr and then change your calculation to this:
function va_kontakt() {
return (pers_nr == globals.param_persnr);
}
But then again, I don’t really know what you are trying to do.
Maybe you can explain your usecases, then we can probably help you better.
I try to explain to you, what I want to do. On my form, there is a list of customers on the left hand side. Each customer has one ore more contact-person, which are listed on the right side. (<- the table view I am talking about)
Now the form-user has to tick in the contact list, only one person, who will be contacted defaultly. That’s why I insert this code into the onAction-event of the added checkbox (the suggestion of “Joas” is already implemented).
function onAction(event) {
globals.vakontakt_persnr = persnr
var curIndex = foundset.getSelectedIndex()
for (var i = 1; i <= foundset.getSize(); i++) {
if (i != m_curIndex) {
foundset.getRecord(i).va_kontakt = false
}
}
}
This code is running trough all contact-persons of this customers and deselects all persons exept the choosen one.
The information which person is check is stored into the customer-table.
When the user selects a customer, I am NOW running this code
function onSelection(param_persnr) {
globals.vakontakt_persnr = param_persnr
}
I also edited the non restored calculation in my contact-person table, just like “Joas” suggested me:
function va_kontakt()
{
return (persnr == globals.vakontakt_persnr);
}
…but it still isn’t working.
[attachment=0]SolAsCheck.PNG[/attachment]
So, i just for fun set the the “displayType” of the named field from “check” to “text_field” and i coundn’t believe my eyes: I works!! …but it still doesn’t work with a check??
[attachment=1]SolAsText.PNG[/attachment]