Giter Club home page Giter Club logo

Comments (11)

trco avatar trco commented on July 30, 2024

@bguerrero5 I don't know how django-select2 implements select2 but you could load select2 js and css, select your dropdown within the script living in your form's html and run .select2() on it.

<form method="post" action="">
  {% csrf_token %}

  <div class="modal-header">
    ...
  </div>

  <div class="modal-body">
    {% for field in form %}
      ...
    {% endfor %}
  </div>

  <div class="modal-footer">
    ...
  </div>
</form>

<script type="text/javascript">
  $(function () {
     $(".your-class").select2();
  });
</script>

from django-bootstrap-modal-forms.

bguerrero5 avatar bguerrero5 commented on July 30, 2024

Thank for the fast response @trco. It is still not working. I am not sure whats causing the problem. I am also using crispy froms. Do you think that could be the problem?

from django-bootstrap-modal-forms.

trco avatar trco commented on July 30, 2024

@bguerrero5 You should provide some error log or code so I can see what's happening. It's hard to debug on ''for some reason django-select2 drop down does not work''.

from django-bootstrap-modal-forms.

bguerrero5 avatar bguerrero5 commented on July 30, 2024

@trco well I am not getting any error with my interpreter. But, in the console at the browser developer tools i can see a couple of error with the java-script. Attached you can find some screenshots of this errors. The screenshots have been uploaded in the order they appear in the browser.

ScreenShoot1
Screenshot
Screenshot2
Screenshot3
Screenshot4
Screenshot5

from django-bootstrap-modal-forms.

trco avatar trco commented on July 30, 2024

@bguerrero5 Is it possible that you didn't include select2 js and css files together with my proposed solution? You're calling select2 function on an element, but the function obviously doesn't exist.

from django-bootstrap-modal-forms.

bguerrero5 avatar bguerrero5 commented on July 30, 2024

@trco yeah, i am calling the select2 function. it looks like this. I am not really good with java-script but i believe it is right.

{% load static %}
{% load crispy_forms_tags %}

{% csrf_token %}
{{ title }}
×
{% crispy form %}
<script type="text/javascript"> $(function () { $("#id_destination_ou").select2(); }) </script>

from django-bootstrap-modal-forms.

bguerrero5 avatar bguerrero5 commented on July 30, 2024

Sorry, here is a better screenshot.

code

from django-bootstrap-modal-forms.

trco avatar trco commented on July 30, 2024

@bguerrero5 You should load js and css for select2. Either download it to your static folder and link to it or link to select2 cdns as written in their docs.

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/js/select2.min.js"></script>

from django-bootstrap-modal-forms.

bguerrero5 avatar bguerrero5 commented on July 30, 2024

@trco when i load the js and ccs for select2, it still not works. But now i get a different error at the console.

Screenshot

from django-bootstrap-modal-forms.

trco avatar trco commented on July 30, 2024

@bguerrero5 Unfortunately I can't conclude anything from that. I still suggest you to try out select2 without django-select2. Load js and css and than instantiate select2 on fields you get by their ids.

from django-bootstrap-modal-forms.

trco avatar trco commented on July 30, 2024

Closing due to inactivity.

from django-bootstrap-modal-forms.

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.