Page 1 of 1

Change selectBooleanCheckbox from JS

Posted: 15 Sep 2020, 23:36
by minitehnicus
It seems that changing the state of a p:selectBooleanCheckbox to 'checked' from JS doesn't work anymore. More precisely, although the value of the underlying HTML element , the hidden input, does change, the appearance on the page does not (the CSS doesn't change to show the UI as 'checked').
I've tried both ways:
- to directly grab the real checkbox HTML input via document.getElementById() and do cboxEl.checked = true;
- to use the widget client side API and call widget.check();
Same happens for p:selectManyCheckbox.
I also tried to run a JS snippet against the official PF demo page, same result.

PF 8.0.4.
Payara 4.1
Chrome/Edge

Re: Change selectBooleanCheckbox from JS

Posted: 16 Sep 2020, 14:32
by Melloware
Works for me?

Go here: https://www.primefaces.org/showcase/ui/ ... kbox.xhtml

Press F12 and open Chrome Console and type..

Code: Select all

PrimeFaces.widgets.widget_j_idt725_j_idt727.check();


it checks the Basic box for me?

Re: Change selectBooleanCheckbox from JS

Posted: 16 Sep 2020, 18:24
by minitehnicus
I'll take back the widget.check() related comment, it is working, sorry for the confusion.
Now, on the same page, trying

Code: Select all

document.getElementById('j_idt725:j_idt727_input').checked=true;
has no visual effect. I'm pretty I used this in PF 6.x and it was working. I'm trying to directly use the element to init the value the via a JS snippet part of a reusable form and work around the widgets not being available at that moment (before the full page load).

Re: Change selectBooleanCheckbox from JS

Posted: 16 Sep 2020, 19:10
by Melloware
Hmmm looking at the code I am not sure if this worked. Looking back through Git it has been this way since PF 6.2, 7.0, 8.0 as far as I can tell.

How far back in PF did you know that it worked? What PF version?

Re: Change selectBooleanCheckbox from JS

Posted: 16 Sep 2020, 19:54
by minitehnicus
It may have been PF 6.0. or 6.1, I just jumper directly to 8.0.
This was an old form we had deployed in 2017 and was accepted as working (more precisely, it was a p:selectManyCheckbox and i would iterate and set the individual checkboxes). I just realized these days, when trying to add a separate checkbox, that the old stuff it doesn't work anymore.
Thanks for the quick feedback!

Re: Change selectBooleanCheckbox from JS

Posted: 16 Sep 2020, 19:58
by Melloware
OK then i recommend updating your code. My guess is between 6.0 and 8.0 that functionality was removed because of some other feature or bug fix etc.

Re: Change selectBooleanCheckbox from JS

Posted: 16 Sep 2020, 20:31
by minitehnicus
While I can work around it for this particular case, I think the question about the expected behavior still remains. I mean, it's a fair assumption that by modifying the underlying DOM element, the change should be visible in the wrapping PF component/UI? Currently the UI gets out of sync. Also, the onchange doesn't fire either when.

Re: Change selectBooleanCheckbox from JS

Posted: 16 Sep 2020, 20:46
by Melloware
I don't think you should be manipulating an underlying hidden DOM Input. You should be interacting with the widget right?

Re: Change selectBooleanCheckbox from JS

Posted: 16 Sep 2020, 20:55
by minitehnicus
Well, I can't totally disagree, but it's a debatable thing. I'll move on with a different approach.
Thanks!