D
D
Daniel Pasko2018-02-15 23:26:14
API
Daniel Pasko, 2018-02-15 23:26:14

Why does Yandex.Map have autofocus for input?

There is a page that hosts a map through an API to calculate shipping costs. The standard routePanelControl with one active field is used.
Link to the page: rabota.skorinia.bget.ru .
Problem : after the page is loaded, the address input field gets focus (via js, there is no autofocus attribute).
Question : how to remove this autofocus? Is there a ban on writing JS or is there some method/call attribute/etc to solve this problem?
Card calling code:

ymaps.ready(mapInit);
        var myMap;


        function mapInit() {
                // Выбираем стоимость за км
                var DELIVERY_TARIFF = 0;
                if ( summaryMass > 1500 ) {
                  DELIVERY_TARIFF = ppkHeavy
                } else {
                  DELIVERY_TARIFF = ppkLight
                }
                // Минимальная стоимость.
                    MINIMUM_COST = 500,
                    myMap = new ymaps.Map('delivery-map', {
                        center: [54.714968, 55.977592],
                        zoom: 15,
                        controls: []
                    }),
                // Создадим панель маршрутизации.
                    routePanelControl = new ymaps.control.RoutePanel({
                        options: {
                            // Добавим заголовок панели.
                            maxWidth: 300,
                            showHeader: true,
                            title: 'Расчёт доставки'
                        }
                    }),
                    zoomControl = new ymaps.control.ZoomControl({
                        options: {
                            size: 'small',
                            float: 'none',
                            position: {
                                bottom: 145,
                                right: 10
                            }
                        }
                    });
                // Пользователь сможет построить только автомобильный маршрут.
                routePanelControl.routePanel.options.set({
                    types: {auto: true}
                });

                 //Если вы хотите задать неизменяемую точку "откуда", раскомментируйте код ниже.
                routePanelControl.routePanel.state.set({
                    fromEnabled: false,
                    from: 'Уфа, улица Сун-Ят-Сена, 11'
                 });

                myMap.controls.add(routePanelControl).add(zoomControl);

                // Получим ссылку на маршрут.
                routePanelControl.routePanel.getRouteAsync().then(function (route) {

                    // Повесим обработчик на событие построения маршрута.
                    route.model.events.add('requestsuccess', function () {

                        var activeRoute = route.getActiveRoute();
                        if (activeRoute) {
                            // Получим протяженность маршрута.
                            var length = route.getActiveRoute().properties.get("distance"),
                            // Вычислим стоимость доставки.
                                price = calculate(Math.round(length.value / 1000)),
                            // Создадим макет содержимого балуна маршрута.
                                balloonContentLayout = ymaps.templateLayoutFactory.createClass(
                                    '<span>Расстояние: ' + length.text + '.</span><br/>' +
                                    '<span style="font-weight: bold; font-style: italic">Стоимость доставки: ' + price + ' р.</span>');
                            // Зададим этот макет для содержимого балуна.
                            route.options.set('routeBalloonContentLayout', balloonContentLayout);

                            deliveryLength = length.value;
                            deliveryCost = price;
                            $deliveryLengthSpan.text(deliveryLength);
                            $deliveryCostSpan.text(deliveryCost);
                            $deliveryLength.val(deliveryLength);
                            $deliveryCost.val(deliveryCost);

                            $('#ORDER_PROP_20').val(deliveryLength);
                            submitForm();
                        }
                    });
                });
                // Функция, вычисляющая стоимость доставки.
                function calculate(routeLength) {
                    return Math.max(routeLength * DELIVERY_TARIFF, MINIMUM_COST);
                }
            }

Link to the same map in the Yandex sandbox: https://tech.yandex.ru/maps/jsbox/2.1/deliveryCalc...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
studio_orange, 2018-04-10
@studio_orange

Faced a similar problem, unfortunately the autofocus option set to false does not solve the problem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question