Jump to content

InputfieldChosenSelect


LostKobrakai

Recommended Posts

InputfieldChosenSelect

This topic (https://processwire.com/talk/topic/71-categorizingtagging-content/) showed the need for a Inputfield that would provide a real tagging UI to be useable with FieldtypePage. It uses the chosen library, which can be found here http://harvesthq.github.io/chosen/. It's meant for MultiPageFields and works kinda like asmSelect, but with a different skin.

post-874-0-37585200-1422635930_thumb.png

Features:

  • Inline adding of new tags, which will then generate the corresponding pages.
  • Sortable tags.

Usage

  • Install the Module
  • Edit your pagefield and choose InputfieldChosenSelect as inputfield.
  • Use Enter or Tab to create new Pages with the currently typed name.
  • Enter will fill in the tab currently selected in the dropdown.

http://modules.processwire.com/modules/inputfield-chosen-select/

https://github.com/LostKobrakai/InputfieldChosenSelect

Edited by LostKobrakai
Removed "approval pending"
  • Like 19
Link to comment
Share on other sites

Is there a way to make readme-images, which come from github, work in the module directory?

Like this: <img src='https://github.com/LostKobrakai/InputfieldChosenSelect/raw/master/screen.png' /> in your README

Since this will be the modules support forum, please add instructions here on how to install and use it. Also add in your README, thanks.

Edited by kongondo
Link to comment
Share on other sites

@LostKobrakai - just playing with this now and I like it - thanks, but there is a bug :)

In InputfieldChosenSelect.js you have:

$(".InputfieldPageTags select[multiple=multiple]").each(function() {

I am not actually sure how that would ever work since that approach would need the name of the field, eg if your field name is: tags

$(".Inputfield_tags select[multiple=multiple]").each(function() {

but this also works and won't be dependent on the field's name:

$(".InputfieldChosenSelect select[multiple=multiple]").each(function() {
  • Like 1
Link to comment
Share on other sites

Features on the "maybe" list:

  • Inline adding of new pages.

This is in-built in ProcessWire and it already works with your Inputfield. I have tested and it works fine unless I am missing something?

A request: Do you know if it is possible to sort the tags by drag and drop like in asmSelect? In your case this would have to be horizontal, of course..

  • Like 1
Link to comment
Share on other sites

@adrian

Shoot, renamed the module locally from InputfieldPageTags to InputfieldChosenSelect, that's why it was still there :) Fixed it.

@kongondo

With inline I mean really in the field where the tags are, so that new pages are also shown in a tag ui if you hit tab or enter. Currently you can only use the autocomplete in this field and add pages below. 

  • Like 1
Link to comment
Share on other sites

I see, but adding pages below has the advantage of being able to add multiple pages in one swoop. I wouldn't want to reinvent the wheel myself, but of course, it's your decision :-)

I edited my post above: Did you see my request? 

Edited by kongondo
Link to comment
Share on other sites

No offense kongondo, but I would actually really like to see the inline way of adding new tags/pages - Since they are already typing, I think that is what many users would expect to be able to do, rather than needing an additional field. 

Nico's https://github.com/NicoKnoll/TextboxList works like this, but of course it would be great to have this in this module so everything is connected to the page field.

  • Like 1
Link to comment
Share on other sites

I wouldn't reinvent much, I would just add the ability to add new tags and in the background, as this works kinda like asmSelect, it would just add items to a select input. To the request of sorting these. It's not possible out of the box, as the library is meant to be a progressive enhancement for selectboxes, where you're normally not able to sort stuff. I'll see if this would be addable with a little jQueryUI's sortable.

  • Like 2
Link to comment
Share on other sites

Love the enhancements, but I am getting something weird - if I only enter 2 characters and then hit enter, it creates a new tag for to match those 2 characters, and then randomly adds a second tag to the list.

post-985-0-20394300-1422636666_thumb.png

Then hit enter and I get this:

post-985-0-24994000-1422636860_thumb.png

 
Edited by adrian
Fixed incorrect attachments
Link to comment
Share on other sites

Nice stuff.

A question though. If i remember correctly Chosen loads the entire dataset into the DOM. I'm wondering if this could potentially lead to performance issues when working with a lot (thousands) of pages to choose from. Solutions like select2 or selectize.js (both jQuery based) allow for partial loading of remote datasets in some form. Maybe you chose Chosen for a good reason but i was just wondering.

Link to comment
Share on other sites

If i remember correctly Chosen loads the entire dataset into the DOM. 

I don't know about all the other inputfields, but chosen is based on the exact multi select inputfield, which asmSelect is built on. I don't know about the performance of the library itself, but the base DOM containes all elements for both inputfields.

Link to comment
Share on other sites

Btw, seems the inline creation of new tags changes the tag's title case to lower case (must be the js). Since this are used to create page titles, is it possible to change this behaviour? i.e. If I enter the tag 'Tech', I expect that and not 'tech'. 

Link to comment
Share on other sites

  • 2 weeks later...

Just a quick request - can you make it possible to override these:

    AbstractChosen.default_multiple_text = "Select/Enter tags";
    AbstractChosen.default_single_text = "Select an Option";
    AbstractChosen.default_no_result_text = "No results match";

Thanks again for this - it's coming in very handy, although client feedback unfortunately is saying that the "Tab" to create a new tag is confusing - any chance you can revisit making Enter work in all situations? Sorry for sounding demanding :)

Link to comment
Share on other sites

From the api you can just use these as with all options available: https://harvesthq.github.io/chosen/options.html.

$inputfield->setChosenOption('no_results_text', "Text");
$inputfield->setChosenOption('placeholder_text_multiple', "Text");
$inputfield->setChosenOption('placeholder_text_single', "Text");

I don't know if that's enough for you to hook ::render and inject these. 

Regarding the Tab / Enter situation. I'm quite good in js by now, but the sourcecode of chosen is still somewhat complex. The last time I searched I didn't find a way to check if there are still elements left in the dropdown or not. I'll take another look into it tomorrow.

Link to comment
Share on other sites

Awesome - so much better with Enter working to add tags - thank you!

As for the no results/placeholder text - I might just go with some jquery.

Thanks again for a fantastic job on this - it really is the best solution for tags fields!

  • Like 2
Link to comment
Share on other sites

Just had one more thought for you - how hard do you think it would be to also offer this as an inputfield for Ryan's new Options fieldtype, in addition to the Pages fieldtype that is currently uses. Thought it might be nice because with tags it is often unlikely that you actually need these to be accessible via a URL, hence no real need for having them as pages now that we have this new fieldtype. 

Just thinking out loud if you are looking for something to do :)

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...