Code Monkey home page Code Monkey logo

Comments (8)

asyncee avatar asyncee commented on June 5, 2024 4

For me, django-easy-select2 is lightweight wrapper on select2 library, which provides easy-to-use basic select2 functionality in a django project.
If you need feature-rich solution, i recommend you to look at the latest django-select2 library, which have ajax loading support.

Anyway, if anyone really wants this functionality in django-easy-select2, please feel free to contribute.

from django-easy-select2.

johnraz avatar johnraz commented on June 5, 2024

👍

from django-easy-select2.

asyncee avatar asyncee commented on June 5, 2024

We need an intuitive and easy to use solution.

Select2 is highly configurable, so there should be no constraints on its config.
Django-select2 approach looks too complicated for me, also there are too many constraints. Well, maybe it is ok for most of users, what do you think?

I think, it is possible to create external select2 configuration file (js) with all options defined in some object, for example:

var user_field_options = {
    width: '400px'
}

That file can be attached to the select2 form (using form Media class) . Then we can configure select2 widget like this:

field = forms.ChoiceField(choices=..., widget=Select2(select2attrs='user_field_options'))

This approach is working, i tested it locally, but there is a problem that Select2's ajax can not be used with select fields, so some converting machinery needed.

This approach is more flexible, because you deal with pure javascript configuration, so you can do whatever you want without constraints, it looks good to me. Also your frontend javascript coders can modify select2 behaviour without modifying python code.

Well... Any ideas? :)

from django-easy-select2.

johnraz avatar johnraz commented on June 5, 2024

I like the idea of having a separated js config, it's indeed the most flexible solution.

Though, I think the ajax url should be provided as a widget option too, we are much likely to get it via reverse which won't be available in the js code.

What do you mean exactly that select2's ajax can not be used with select fields ?

from django-easy-select2.

asyncee avatar asyncee commented on June 5, 2024

Jonathan, you are correct about using reverse or resolve_url, i will think about it.

When i try to do $('#some-select').select2({ajax: function(){}}) an exception raised:

Error: Option 'ajax' is not allowed for Select2 when attached to a <select> element.

from django-easy-select2.

johnraz avatar johnraz commented on June 5, 2024

Ha yes, it has to be attached to an input (it makes sense as we don't know beforehand the options of the select), I guess the only solution is to create a Select2Ajax widget that inherit from TextInput or something along these lines.

from django-easy-select2.

johnraz avatar johnraz commented on June 5, 2024

FTR: https://github.com/johnraz/django-cms/blob/a18abac5b5cde2546836e5e8487c3379021b60ec/cms/forms/widgets.py#L128

I did something alike there.

from django-easy-select2.

sebastien247 avatar sebastien247 commented on June 5, 2024

👍

from django-easy-select2.

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.