Git Product home page Git Product logo

Comments (3)

dibene avatar dibene commented on August 27, 2024

$('#your select id').select2entity().select2('open');
$('.select2-search__field').eq(0).val('your value').trigger('input');

from select2entity-bundle.

beefydog avatar beefydog commented on August 27, 2024

No problem setting the value programmatically (some clever javascript was required to programmatically add the attribute selected="selected") - the problem is that when I post the page back, there is no longer a selected value (this only happens when loading via jquery ajax - or adding options by any method - javascript or jquery). .trigger('change') has no effect (it triggers, for sure, but it still forgets what is set. What good is an HTML Select if you can't post back a selection or selections?

from select2entity-bundle.

matpowel avatar matpowel commented on August 27, 2024

I see this is an old issue but I've searched for hours on this and there doesn't seem to be a satisfactory way to achieve this. It seems like an obvious use case, there are various reasons to want to programmatically insert select2 search term. In my case I am using tagging and a user might have saved a draft version of my object with a "tagged" option that I want to remember, but when I reload the page I want to represent it as a tagged object, not an existing option.

The big issue I have is that the createTag method never gets called when you do the option append / trigger change method recommended most places. I simply want to mimic a user typing a search term and pressing enter to create a tag instead of selecting an existing option but I might have 20 on one page and don't want to go through opening dropdown and populating popup boxes.

Select2 3.5.x apparently had a method to dynamically mimic the search term, does 4.x+ really have nothing like that?

from select2entity-bundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.