Page 1 of 1

Inverting selection on SelectManyMenu

Posted: 13 Dec 2021, 22:53
by benoit
Hello,

I'm looking for a way to invert the selection in a SelectManyMenu before sending the request.

I'm totally new in JQuery, but regarding the Client Side Primefaces SelectManyMenu documentation, I understand that i can retrieve allItems and loop on it for selecting Item or unselecting item, but I reach 2 problemes.

1) I'm don't know how determining if the component is selected or not. Is there an undocumented method or a way to know that? I do something (see above) but it's not tested yet and seem un reliable
2) When I try to use the method (un)selectItem on the object in the allItems list, I get a javascript Error

Here is the code (for testing):

Code: Select all

function test() {
	PF('diversList').allItems.each(function(i, obj) { 
		if(this.className == "ui-selectlistbox-item ui-corner-all ui-state-highlight") //i.e. Selected
			PF('diversList').unselecItemt(obj)
		else 
			PF('diversList').selectItem(this)
	})
}

And the error message :

Code: Select all

components.js?ln=primefaces&v=11.0.0&e=11.0.0:25 Uncaught TypeError: a.removeClass is not a function
    at c.unselectItem (components.js?ln=primefaces&v=11.0.0&e=11.0.0:25)
    at c.unselectItem (components.js?ln=primefaces&v=11.0.0&e=11.0.0:27)
    at c.e.<computed> [as unselectItem] (core.js?ln=primefaces&v=11.0.0&e=11.0.0:24)
    at HTMLLIElement.<anonymous> (List.xhtml:9)
    at Function.each (jquery.js?ln=primefaces&v=11.0.0&e=11.0.0:2)
    at S.fn.init.each (jquery.js?ln=primefaces&v=11.0.0&e=11.0.0:2)
    at test (List.xhtml:7)
    at <anonymous>:1:1
unselectItem @ components.js?ln=primefaces&v=11.0.0&e=11.0.0:25
unselectItem @ components.js?ln=primefaces&v=11.0.0&e=11.0.0:27
e.<computed> @ core.js?ln=primefaces&v=11.0.0&e=11.0.0:24
(anonyme) @ List.xhtml:9
each @ jquery.js?ln=primefaces&v=11.0.0&e=11.0.0:2
each @ jquery.js?ln=primefaces&v=11.0.0&e=11.0.0:2
test @ List.xhtml:7
(anonyme) @ VM10262:1

Re: Inverting selection on SelectManyMenu

Posted: 23 Dec 2021, 15:00
by benoit
Hello,

Can someone Help?

Re: Inverting selection on SelectManyMenu

Posted: 08 Apr 2022, 08:07
by bonjovi
SelectManyMenu's are great for grouping related items together. For example, you can group options for each color of a different type of shirt. However,wordle websiteif you want to invert the selection, you can't just keep adding a new SelectManyMenu. io games