We're using the koenpunt fork of chosen (https://github.com/koenpunt/chosen) that adds a cool new feature that let's you add new options if the one you type isn't found (https://github.com/harvesthq/chosen/pull/166).

This functionality works well if you are using the Select (or other) module, but it needs a bit of tweaking in chosen.js in order to support these new Chosen library options.

Comments

dave reid’s picture

Status: Active » Postponed

Since this hasn't landed in the main repo yet, I'm going to go ahead and mark this as postponed. Don't feel you have to do anything based on this issue, but it will be a nice place to share patches for those of us using the fork.

dave reid’s picture

StatusFileSize
new797 bytes
galaxor’s picture

Status: Postponed » Needs review
StatusFileSize
new2.62 KB

Hi. I was on a plane and didn't see that there had been other work on this. I did a quick little select_or_other integration that isn't quite as integrated as the other patch, but was quick to implement. If you just want *some* select_or_other integration, this is a small change that could go in while the rest of the work is done on the other branch.

dave reid’s picture

@galaxor: Can you please file a new issue for your patch? That's more about allow Chosen to be selected for select_or_other widgets. The patch I've provided is for the create new option feature only.

Garrett Albright’s picture

Does the current koenpunt fork work for anyone? After (figuring out how to build the damn thing and) installing it, it doesn't seem to want to put any options in the drop-down - it just works like a text field. Did the options change or something?

dave reid’s picture

Issue summary: View changes
StatusFileSize
new770 bytes

Re-rolled against 7.x-2.0-beta1.

dave reid’s picture

Revised patches against 7.x-2.0-beta1 and 7.x-2.x-dev.

dave reid’s picture

Re-rolled for 7.x-2.x again and fixed liszt:updated should be chosen:updated with the latest library.

dave reid’s picture

StatusFileSize
new819 bytes
rv0’s picture

Works fine here, thanks a lot!

@Garrett Albright
You don't have to build it, there's releases:
https://github.com/koenpunt/chosen/releases

rv0’s picture

One small comment..

I hate the fact that it shows the "other" textbox, I'd rather have it show the option in the select itself.

I quickhacked this in by changing:

        chosen.create_option = function(value) {
          this.form_field_jq.val('select_or_other').change().trigger('chosen:updated');
          this.form_field_jq.parents('.select-or-other').find('input.select-or-other-other').val(value).change();
        }

to:

        chosen.create_option = function(value) {
          this.form_field_jq.val('select_or_other').trigger('chosen:updated');
          this.form_field_jq.parents('.select-or-other').find('input.select-or-other-other').val(value).change();
          this.select_append_option({value: value, text: value});
        }

Basically, removes triggering the change event and adds the option to the select.

Mołot’s picture

@rv0 Any chance you can incorporate your change into a patch file? I'd "review" it, then, and hopefully we could get it incorporated in next version.

rv0’s picture

@Mołot: sure, but I was thinking people would prefer it configurable.

In any case, we switched to Select2.js for our usecase because it allows adding elements out of the box, and just by pressing enter (no special clicks required).

Patch in attach.

markdc’s picture

Has there been any progress on this? Has Chosen come a little further in 3 years? I don't want a 'click for other' method. I want to type and press return to create new.

I've unsuccessfully tried to get this functionality with other modules (Select2, Select2Widget, Autocomplete Deluxe) and several combinations of patches — nothing works. But as Chosen is my Select UI of choice, I'd prefer to stay with it anyway.

Also, I don't know if it's because I'm using OG Vocab... That probably complicates things, huh?

ohmdesbois’s picture

+1