Comments (3)
$('#your select id').select2entity().select2('open');
$('.select2-search__field').eq(0).val('your value').trigger('input');
from select2entity-bundle.
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.
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)
- How to change the value used from the AJAX response? HOT 2
- I can't select an option HOT 1
- How to restrict adding duplicate tags? HOT 7
- Need help to use it with sonata admin HOT 2
- optgroup option ?
- [EntitiesToPropertyTransformer] Entities result order issue
- Neither the property .... nor one of the methods ... exist and have public access in class "Doctrine\ORM\PersistentCollection"
- Error with doctrine/persistence 2.0.0 HOT 1
- Supporting CollectionType
- Add closeOnSelect option
- Filter doesn´t found HOT 2
- Drop jQuery?
- Argument 1 passed to Tetranz\Select2EntityBundle\Form\Type\Select2EntityType::__construct() must be an instance of Doctrine\Persistence\ManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Registry given
- How to set header X-AUTH-USER info from bundle?
- Change of query_parameters is not recognized when done in onchange-function HOT 1
- Dont work with MongoDB DocumentManager
- Note from the maintainer of this project. HOT 7
- Initialize error javascript
- Prefill select on form load wich remote_route
- Is this compatible with symfony 6? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from select2entity-bundle.