Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-04-22 15:15:40

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

multiple select preference saving?

Hi,
I’m playing with ways to set theme prefs (see also this post). I can use text and radio inputs as well as select lists (with this kind of functions) but it seems that multiple selects don’t work. It is probably normal as the core prefs don’t use them but do you think that it could become available in the future or should I use text inputs and let users look for the images id’s, sections names, etc. under the related tabs to fill the field like we do with the article_image field?

Last edited by NicolasGraph (2016-04-22 15:36:40)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#2 2016-04-28 20:25:55

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: multiple select preference saving?

Salut Nicolas,

if you mean the core selectInput() function, it could easily be extended to multiple selects. To indicate that we need a multiselect, one could pass e.g. an array of preselected values instead of string as its third $value argument. Does this make sense for you/anyone?

Offline

#3 2016-04-28 23:17:48

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: multiple select preference saving?

etc wrote #298874:

Salut Nicolas,

Salut Oleg, merci de ta réponse…
In fact, I’m already able to display a multiselect in the prefs panel with a custom function but multiple values can’t be saved as far as I tried; that’s the issue for me now.

Edit: Extended the selectInput function to allow multiselects would make sens, if, and only if, we could save multiple values…
Edti#2: …and get them easily, as a comma separated list in my case.

Last edited by NicolasGraph (2016-04-29 08:19:50)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#4 2016-04-29 12:03:30

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: multiple select preference saving?

Ah, got it. I have created a branch that stores array preferences as comma-separated lists, please try it with your select widget.

Offline

#5 2016-04-30 09:45:00

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: multiple select preference saving?

etc wrote #298880:

Ah, got it. […] please try it with your select widget.

Thanks, I still need to think about a better way to build my select input, but it works and helped me to figure out where I had an other problem.

Now, yes a way to use selectInput for multiselects would be great, and wouldn’t it be useful for the future custom fields?

Another thing I’m wondering is: should I display a multiselect list of all articles or all images to select few of them? Doesn’t it cause performances issues if there is a lot of content?

Last edited by NicolasGraph (2016-04-30 09:45:59)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#6 2016-04-30 12:17:30

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: multiple select preference saving?

NicolasGraph wrote #298886:

Now, yes a way to use selectInput for multiselects would be great, and wouldn’t it be useful for the future custom fields?

I think it would, and will add it for testing later today. But, before merging with master, we need to hear Stef’s “be my guest” re future custom fields :)

Another thing I’m wondering is: should I display a multiselect list of all articles or all images to select few of them? Doesn’t it cause performances issues if there is a lot of content?

I think UI issue will be more annoying than performance

Offline

#7 2016-04-30 12:40:20

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: multiple select preference saving?

etc wrote #298888:

I think UI issue will be more annoying than performance

You’re rigth, I’ll probably restrict multiselects to short lists.


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#8 2016-04-30 14:18:47

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: multiple select preference saving?

NicolasGraph wrote #298886:

Now, yes a way to use selectInput for multiselects would be great

Done. To obtain a multiselect box with preselected values, call

selectInput('my_name', array('possible', 'selected', 'values'), array('selected', 'values'), ...);

For prefs multiselect, you typically need to define a handler like

function my_select($name, $val) {
    $array = array('apple'=>'Apple', 'banana'=>'Banana');
    return selectInput($name, $array, do_list_unique($val));
}

and create a pref with my_select html handler.

Last edited by etc (2016-04-30 14:29:19)

Offline

#9 2016-04-30 15:02:46

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: multiple select preference saving?

etc wrote #298892:

Done…

I’d say well done. It works perfectly.


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#10 2016-04-30 16:23:29

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: multiple select preference saving?

etc wrote #298892:

Done

Bravo! Been meaning to do this for ages and kept forgetting. That’ll save a load of code in my plugins as I move forward and 4.6-ise them, ‘cos I can strip out the custom handlers for multi-selects.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#11 2016-04-30 17:00:55

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: multiple select preference saving?

Thanks guys, nice to be supported. It has a small flaw, though: if nothing is selected, the pref is not sent at all and thus remains unchanged. I don’t know how to fix it, ideas welcome.

Offline

#12 2016-04-30 17:11:20

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: multiple select preference saving?

etc wrote #298897:

Thanks guys, nice to be supported. It has a small flaw, though: if nothing is selected, the pref is not sent at all and thus remains unchanged. I don’t know how to fix it, ideas welcome.

Not sure but can’t you enable blank_first for multiselects and select this option if nothing is selected?

Last edited by NicolasGraph (2016-04-30 17:50:23)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

Board footer

Powered by FluxBB