Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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,689
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,689
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,689
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

#25 2016-05-02 11:41:49

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

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

#26 2016-05-02 11:49:50

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

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…?


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

Offline

#27 2016-05-02 21:03:30

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

Re: multiple select preference saving?

I have added checkbox sets to the collection.

Offline

#28 2016-05-03 13:54:27

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

Re: multiple select preference saving?

etc wrote #298920:

I have added checkbox sets to the collection.

That could be useful; we now have a great prefs package.
Thanks for your work and your pedagogy!


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

Offline

#29 2016-05-03 15:07:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,499
Website GitHub

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

#30 2016-05-03 15:23:31

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

Re: multiple select preference saving?

Bloke wrote #298943:

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.

Yes, I saw your note on Github ; no worry. I’m trying to get that working for now.

Last edited by NicolasGraph (2016-05-03 18:32:05)


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

Offline

Board footer

Powered by FluxBB