Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Offline
Re: multiple select preference saving?
etc wrote #298902:
What about an empty hidden selected option that will always be sent, and filter on arrival?
But… How do you always send this option?
I tried to add an hidden option but if it’s enable, it can be unselected by clicking on an other option, and if it’s disable, it’s not sent.
Offline
Re: multiple select preference saving?
What do you think about that?
selectInput changes:
…
+ $hidden = ($multiple ? n.'<select name="'.$name.'" style="display: none">.n.<option value="" selected="selected"> </option>.n.</select>' : '');
- return n.'<select'.$atts.$multiple.'>'.n.join(n, $out).n.'</select>'; // TODO: use jQuery UI selectmenu?
+ return $hidden.n.'<select'.$atts.$multiple.'>'.n.join(n, $out).n.'</select>'; // TODO: use jQuery UI selectmenu?
and then in txp_prefs.php
if (is_array($post[$name])) {
+ array_shift($post[$name]);
$post[$name] = implode(', ', $post[$name]);
}
Edited for small improvements.
Last edited by NicolasGraph (2016-05-01 07:37:07)
Offline
Re: multiple select preference saving?
NicolasGraph wrote #298904:
But… How do you always send this option?
I tried to add an hidden option but if it’s enable, it can be unselected by clicking on an other option, and if it’s disable, it’s not sent.
It doesn’t have to be a select. I’ve added a hidden input (with the same name) yesterday, in the spirit of what you suggest, and it works. We just can not have an empty '' value as an option now, but it is not really restrictive, right?
Offline
Re: multiple select preference saving?
etc wrote #298906:
I’ve added a hidden
input(with the same name) yesterday.
L’important c’est de participer… :/
We just can not have an empty
''value as an option now, but it is not really restrictive, right?
It should be ok… ;)
Offline
Offline
Re: multiple select preference saving?
etc wrote #298908:
Oups.. désolé. Tu devrais peut-être t’abonner aux txp github news, ils ne sont pas très envahissants :)
Pas de souci, ça me fait travailler mon php; c’est bon pour la forme !
On another side; my way to filter the values on saving allows the use of empty values ''. This kind of value is saved and can be returned correctly. The problem is that it does not appear as a selected option in the select after saving… Should we try to fix that or empty values are definitly useless? They are, probably.
Offline
Re: multiple select preference saving?
Your approach presumes that the first $post[$name] element always comes from selectInput(), which is not guaranteed. If we want to save empty values, that’s easy to fix: just send name[-1] as hidden value, and remove it server-side. You also must replace do_list_unique() with do_list() to preserve them in selected array.
Offline
Offline
Re: multiple select preference saving?
Technicalities apart, we have to decide whether an empty '' item can be part of an options list: 'apple,,banana'? I would say no, otherwise what is '' itself: an empty list or a list with one empty element? In many places txp already uses do_list_unique() function that removes empty elements by default, so I would adhere to this behaviour.
Offline
Re: multiple select preference saving?
etc wrote #298915:
Technicalities apart, we have to decide whether an empty
''item can be part of an options list:'apple,,banana'? I would say no…
I agree, I can’t really imagine how an empty value would be useful but others may have an other opinion…?
Offline
Offline
Offline
Re: multiple select preference saving?
NicolasGraph wrote #298936:
That could be useful; we now have a great prefs package.
It’s getting better, I agree. Don’t rely on this new function too much right now though, as we’ll probably refactor the parameters later today.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: multiple select preference saving?
Offline