0

I've spend an hour trying to make this jsfiddle splendid selectize modification to stop close (stopPropagation) on option selection , but I am now feeling helpless. Do I have to use some of selectize option for this ? I've read the doc through, but found nothing relevant. The only relevant option seems to be closeAfterSelect, but its default value is false :( Any ideas ?

$('.dropdown').each(function() {
    $_self = $(this);
    $_self.find('select')
        .selectize({ plugins: ['component'], maxItems: 1, closeAfterSelect:false })
        .on('change', function() {
            console.log('Changed value to:', $(this).val() )
            $_self.find('span.value').text( $(this).val() )
            if ($(this).val()) {
                $_self.removeClass('open');
            }
        });
    $_self.find('select').on('click', function(e) { e.stopPropagation(); });
    $_self.find('.dropdown-menu').on('click', function(e) { e.stopPropagation(); });
     $_self.find('.dropdown').on('click', function(e) { e.stopPropagation(); })
});

Once again to clarify - I want the drop down to close only when I press the caret. If I choose any option, I want it to stay open. As you may notice, I've added the stopPropagation method on each class and element possible and yet can't get it work as expected

5
  • A Proof of Concept in a jsbin/jsfiddle would help A LOT.... Commented Jul 29, 2016 at 12:36
  • @MattDiMu thats what his splendid selctize link is Commented Jul 29, 2016 at 12:39
  • It seems that its the dropdown thats the issue and not selectize Commented Jul 29, 2016 at 12:40
  • Well, the link is provided. I need to fix it there Commented Jul 29, 2016 at 12:45
  • @Craicerjack true, didn't see the link. A possible solution should be below as answer. Commented Jul 29, 2016 at 12:58

1 Answer 1

1

The problem is, that the e.stopPropagation() is executed too early and therefore won't do anything. But you may return false the on-change-event:

http://jsfiddle.net/MattDiMu/ozmqek7b/1/

Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I wanted. Thanks much for that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.