populate yesno element

immagine_2023-08-22_151933654.png
 
Try:

JavaScript:
var rbutton = this.get('value');

if(rbutton == "*") {
     jQuery("#lista___Completo").find('label[for="lista___Completo1"]').trigger('click');
} else {
     jQuery("#lista___Completo").find('label[for="lista___Completo0"]').trigger('click');
}
 
great!thank you!
now it works
I have another step now
I have other radiobutton that i use to assign the value to yesno(lista___Completo)
in total 35. If only one is * (not answered) then i should get YES
So i am thinking i should copy the same code for all the radiobutton
But i see in same occasion the final value of yesno is not correctly calculated..depending on the state of the radiobutton..it might get confused
So as i dont need to have it in realtimne may be if i use the onload is better?

Also do i need to change the name of the var(rbutton) for each radiobutton?
 
no the "load" don't work, as if i save it i want to see in the list view he correct value of yesno button.And it will be correct only when loading
I don't see the option "save" though
how this thing can be sorted then?
 
As you have as much as 35 elements, it doesn't make sense to do it like this.

Use the form php plugin like @troester suggested in another thread.
 
  • Like
Reactions: cap
You will probably not notice any additional waiting times with either of those solutions, but form php plugin is just much more suitable for this case.

With form php plugin (onAfterProcess) you should also be able to do it with a query, like:

SELECT id FROM your_table WHERE radio_element = '*'

And if the query gives result, then update yesno element to 1, otherwise to 0.

So you don't need to make 35 if-statements.

Of course this is just a bare example of logic. It needs to be adjusted according to examples in wiki.
 
You will probably not notice any additional waiting times with either of those solutions, but form php plugin is just much more suitable for this case.

With form php plugin (onAfterProcess) you should also be able to do it with a query, like:

SELECT id FROM your_table WHERE radio_element = '*'

And if the query gives result, then update yesno element to 1, otherwise to 0.

So you don't need to make 35 if-statements.

Of course this is just a bare example of logic. It needs to be adjusted according to examples in wiki.
In which part of the wiki i find the examples?
 
very hard for me to understand, as i don't see an option that match mine
First thing i don't know how to set the where condition. (radiobutton='*' or i nee to write again all the radiobutton name's?)

then once the search has selected or not records how toc heck it?
do i need to check the variable $myQuery to see if it empy or not?

and then how to assign value?

i tried with this
$myQuery
->select(array('artBTN','stessoregimeBTN')) (or ->select(array(5,13)) if i need to use the id of the element)
->from('lista')
->where (radiobutton="*")

{
$formModel->updateFormData('lista___Completo', '0', true);
}
else
{
$formModel->updateFormData('lista___Completo', '1', true);
}

most of the the example i find are like this
$sql = "SELECT id, username, email FROM users WHERE username = ?";
and this is much easier to understand..select a group of elements and check one of these elements for the recorded to be selected
in my case i need to select a group of elements and check all of these elements to have a yes or no answer
 
i have seen around the function array search that seems perfect
i d need to select as array alll the radiobutton value
and then search within the array for *
if found yesno si
otherwise no
could be a solution?
 
Okay, I misinterpreted this a bit just looking at this quickly. You would still need to point out all the radiobutton element names in the query, so something like this should work:
PHP:
$mydb = Factory::getContainer()->get('DatabaseDriver')

$mydb->setQuery("SELECT * FROM lista WHERE CONCAT(radio1, radio2, radio3 ... ) LIKE '%*%' ");
$results = $mydb->loadObjectList();

if($results) {
    $formModel->updateFormData('lista___Completo', '0', true);
} else {
    $formModel->updateFormData('lista___Completo', '1', true);
}

P.S. This code is not tested, so you may need to adjust. At least you need to replace radio1, radio2, etc. with your real radiobutton element names (just field name without table name).
 
Last edited:
Probably also an option. You just need to add all your radiobutton values into an array and do an array search for "*".
i have seen around the function array search that seems perfect
i d need to select as array alll the radiobutton value
and then search within the array for *
if found yesno si
otherwise no
could be a solution?
 
i have written this..mixing codes form different examples

$radios = array('lista___artBTN', 'lista___stessoregimeBTN');
$searchValue = "*";
$key = array_search($searchValue, $radios);
if ($key != false)
{
$formModel->updateFormData('lista___Completo', '0', true);
}
else
{
$formModel->updateFormData('lista___Completo', '1', true);
}

i had a change in yesno..then it stopped having effect
is it correct?
this should be in afterprocess? beforestore?

p.s.

trying to do some debugging and i have found that the $radios don't get a vaue but the element name itself..so must be somehting wrong in syntax..parenthesis..'',"" ?
 
Last edited:
i have done some modification and debugging and find that this
$key = array_search($searchValue, $radios);
doesnt handle the resul as i expexted
when it search, if the value searched is not found or if it is found in first position (so it return 0) it is the same
if the searched value, in this case the * is found from the second element and on..then the condition is satisfied
So the true false for $key i think don't work properly in this case
so how do i check?
for now i have set as first element in the array a fake one..so if the real firstelement is * now it$key is 1 and not anymore 0 and like this seems to work
and it must be on beforestore, is correct beforestore?
Is there a better way to solve the $key search issue?
 
Last edited:
You $radios array must be something like
array($formModel->formData['lista___artBTN'],...)
What does it change?
The way i have done works,all value of the array elements are correct.
The problem is that if the first element of the array search meet the criteria the search will return 0, that is false. But in fact should be true!False should come out when no elements meet the criteria...
Arrray search works in this strange way
So for me the problem is the array search or in the false/ true statement
If i put a fake elements in 1st position of the array all works fine
 
Last edited:
Are you absolutely sure that your array contains the actual radio values? If it does, then it's a total mystery for me. You can see the array contents when you add "var_dump" and submit your form. Like:

$radios = array('lista___artBTN', 'lista___stessoregimeBTN');
var_dump($radios);
exit;

Because I cannot also imagine how 'lista___artBTN' would work. It should be formModel like troester said or a placeholder like '{lista___artBTN_raw}' should also work onAfterProcess.
 
As i said the array content is correct, i have printed on screen and it is fine.(used print_r)
The array search returns the position of the items that much the searching value, starting from 0
So first element=0, second element=1 and so on
Example the array is (radio1,radio2,radio3)
Radio1 contain * and
I am searching for *
Array search return 0(for radio1) a
The 0 is considered false and i don t have a correct final result in "if ... = true"
But if i add a fake
(Fake,radio1,radio2,radio3)
Then the search returns 1 and it is TRUE
This way it is working
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top