S
S
Stanislav2020-10-09 12:49:10
JavaScript
Stanislav, 2020-10-09 12:49:10

How to add a click event to the Yandex Maps balloon button?

Hello, I'm trying to hang an on click event on the balloon button,

'balloonContentBody': '<input type="button" value="Выбрать" class="baloon-button">'

$.ajax({
        // получаю метки и балуны
        }).done(function(data){
            data = JSON.parse(data);
            if (data['success'] === true){
                let objectManager = new ymaps.ObjectManager({
                    clusterize: true,
                    gridSize: 32,
                    clusterDisableClickZoom: true
                });
                map.geoObjects.add(objectManager);
                objectManager.add(data['information']);

                let layout = map.getBalloon().getLayout();
                YMaps.jQuery(layout.getRootNodes()).find('.baloon-button').click(function() {
                    console.log('Do something...');
                });
            } else{
                console.log(data['error']);
            }
        });
but i get an error
map.getBalloon is not a function

This option doesn't work either.
$('.baloon-button').on('click', function(){ 
    console.log('Do something...'); 
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav, 2020-10-13
@Chebaa

Eugene replied in a comment

via own balloon template

Something like this
let myBalloonFooterBodyLayout = ymaps.templateLayoutFactory.createClass(
    '<input type="button" value="Выбрать" class="baloon-button">', {
        build: function() {
            myBalloonContentBodyLayout.superclass.build.call(this);
            $('.baloon-button').on('click', function() {
                console.log('Do something...');
            });
        }
    });
let objectManager = new ymaps.ObjectManager({
    contentFooterLayout: myBalloonFooterBodyLayout
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question