Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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)
Offline
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
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)
Offline
Offline
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)
Offline
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
Offline
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
Offline
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
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
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)
Offline