-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add select2 constructor parameters #4
Comments
For this you need to sub-class whatever widget you are using. If you are using a field then you need to find out the widget used by it, sub-class that and pass this new widget to that field. Your widget subclass should override
Make sure your js function already exists before this widget is rendered. If you need your function to run in context of the rendered select2 field then use Initial should work as it does with existing fields and widgets. I guess you already tried that, so I will have to check this. Can you tell me which exact widget or field you are trying to use? |
Maybe you are trying to use a heavy component. I noticed a bug there. It might take a while for me to merge the fix. In the meantime please comment the line I will close this issue when I merge that fix. |
Awesome, thanks for the tip! My structure looks like this:
In both cases, I'm not able to load an initial value. |
Can you please try with the latest code? |
Ive got:
When I try to display the form, I get the following error: 'NoneType' object is not iterable This is triggered in line 279 of django_select2/fields.py in _set_choices
Local vars: self 'utils.fields.CityChoices object' edit: actually, for some reason, the hole site is down because of this edit: The work around I found (so that the hole site doesn't crash), is this:
|
Did you try with
I hope that would be a better fix. Do you see any issues with that? |
I created a fork with that change, and is not working. Anyway, value is a queryset, so "if value" does a len on it, which is not a good idea considering the whole purpose of this is to not load a huge database |
Yes. Actually I noticed one design problem. Auto model fields work out well since they eventually extend |
Can you please check if the branch v3.0.1's code works for you? (https://github.com/applegrew/django-select2/tree/v3.0.1) |
It doesn't crash anymore, but I still can't get initial value. Plus I'm getting an error on heavy_data.js line 183
Uncaught TypeError: undefined is not a function |
This is weird. |
In addition to the html of the page, can you try the latest code from v3.0.1 branch? I made some fundamental changes to Heavy fields, that should facilitate using big data for these fields. See comments of Additionally sine you seem to be using Django models as your data source then why don't you use |
This is the code for my field: http://dpaste.com/hold/795731/ (this explains why I'm not using AutoModelSelect2Field) This is the generated html: http://dpaste.com/hold/795733/ And this is the error is throws in the js console: Uncaught TypeError: undefined is not a function heavy_data.js:183 The line 225 on /create-new-post/ is:
Edit: Oh and this error only occurs when I set an inital value to the form
|
From your code I can see that you let user enter multiple values in the field separated by I see no issues in the generated Html. Do you have any custom JS code? Please download the latest v3.0.1 code and retest. Now it will auto pick the non-minimised version of Select2 js, so it should be easier to debug. I am not sure if this is relevant but note that |
Thank you so much! I changed CityChoices to AutoModelSelect2Field, and everything is working just fine! |
Well then I guess we can close this issue. :-) |
I need to add
So that I can add stuff, not only select the already existing. Also, I haven't been able to add an initial value to django-select2 form fields.
Are this two things supposed to work but I'm not getting, are bugs or are they not possible?
The text was updated successfully, but these errors were encountered: