Change selectBooleanCheckbox from JS

UI Components for JSF
Post Reply
minitehnicus
Posts: 13
Joined: 09 Oct 2013, 16:41

15 Sep 2020, 23:36

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

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

16 Sep 2020, 14:32

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?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

minitehnicus
Posts: 13
Joined: 09 Oct 2013, 16:41

16 Sep 2020, 18:24

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).

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

16 Sep 2020, 19:10

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?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

minitehnicus
Posts: 13
Joined: 09 Oct 2013, 16:41

16 Sep 2020, 19:54

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!

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

16 Sep 2020, 19:58

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.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

minitehnicus
Posts: 13
Joined: 09 Oct 2013, 16:41

16 Sep 2020, 20:31

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.

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

16 Sep 2020, 20:46

I don't think you should be manipulating an underlying hidden DOM Input. You should be interacting with the widget right?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

minitehnicus
Posts: 13
Joined: 09 Oct 2013, 16:41

16 Sep 2020, 20:55

Well, I can't totally disagree, but it's a debatable thing. I'll move on with a different approach.
Thanks!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests