Code Monkey home page Code Monkey logo

Comments (1)

erdem avatar erdem commented on August 17, 2024

The widget won't update if you only change the django form input; you need to trigger the JS class events too. This is actually a nice feature request. It would be better if we managed map updates via a JS event when a marker needs to be added to the map. I will consider implementing this feature in the next major release.

However, there is a solution to handle your case. As I mentioned in my previous reply, you need to call widget class functions through the element's bound data object.

Here is my sketchy implementation to update a field(location) on my django form class. You can apply the same implementation for your ajax call.

<script type="text/javascript">
    (function ($) {
        const widgetClassObj = $("#location-map-elem").data("mwClassObj")
        setTimeout(function () {
            // widgetClass.addMarkerToMap(lat, lng)
            widgetClassObj.addMarkerToMap(51.6575243834443, -0.1548867463910279)  // add marker to map
            widgetClassObj.updateDjangoInput() // update django input
            widgetClassObj.fitBoundMarker() // fix center position for the marker

            setTimeout(function () {
                // you can reset the map with `widgetClassObj.resetMap()`
                widgetClassObj.resetMap()
            }, 5000)

        }, 3000)
    })(jQuery)
</script>

from django-map-widgets.

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.