Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2016-04-30 17:35:39

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

Re: multiple select preference saving?

NicolasGraph wrote #298899:

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

This is an option, though not ideal, because it still needs selecting the “blank” value. Another one is sending an empty value by js if nothing is selected.. what else?

Offline

#14 2016-04-30 17:55:17

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

Re: multiple select preference saving?

etc wrote #298900:

This is an option, though not ideal, because it still needs selecting the “blank” value. Another one is sending an empty value by js if nothing is selected.. what else?

We could force the blank value to be selected (hardcoded) and remove it from the $value array if other values are selected too? Still not ideal…

Last edited by NicolasGraph (2016-04-30 17:56:15)


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

Offline

#15 2016-04-30 18:23:02

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

Re: multiple select preference saving?

What about an empty hidden selected option that will always be sent, and filter on arrival?

Offline

#16 2016-05-01 04:36:37

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

Re: multiple select preference saving?

etc wrote #298902:

What about an empty hidden selected option that will always be sent, and filter on arrival?

Yes! That’s what I tried to imagine.


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

Offline

#17 2016-05-01 06:09:24

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

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.


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

Offline

#18 2016-05-01 06:34:47

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

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">&#160;</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)


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

Offline

#19 2016-05-01 07:37:20

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

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

#20 2016-05-01 07:49:38

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

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… ;)


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

Offline

#21 2016-05-01 09:29:58

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

Re: multiple select preference saving?

NicolasGraph wrote #298907:

L’important c’est de participer… :/

Oups.. désolé. Tu devrais peut-être t’abonner aux txp github news, ils ne sont pas très envahissants :)

Offline

#22 2016-05-01 10:26:19

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

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.


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

Offline

#23 2016-05-01 11:13:07

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

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

#24 2016-05-01 11:21:42

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

Re: multiple select preference saving?

etc wrote #298910:

Your approach presumes that the first $post[$name] element always comes from selectInput(), which is not guaranteed.

Oh, ok, I thought it was.


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

Offline

Board footer

Powered by FluxBB