0.0.16 form mover

This commit is contained in:
SBD
2025-01-14 16:19:40 +03:00
parent cfe1a9d585
commit e938d5915a
5 changed files with 59 additions and 15 deletions

View File

@@ -76,4 +76,34 @@ function addCustomDataToFormData(el, formData) {
}
return formData;
}
function getCargoTypesWTypeTransport (data) {
let type_transport = data.type_transport;
let owner_type = data.owner_type;
let success_callback = data.success_callback;
let error_callback = data.error_callback;
if (!type_transport || !owner_type) return;
let request_data = {
type_transport: type_transport,
owner_type: owner_type,
}
let request = new api({
url: '/routes/get_cargo_type_by_transport_type/',
data: request_data,
data_type: 'json',
success: success_callback,
error: error_callback,
})
request.ajaxRequest()
}
function getFormOwnerType(el){
let form = el.closest('form');
let owner_type = form.dataset.owner_type;
return owner_type;
}

View File

@@ -47,4 +47,18 @@ function makePosterOrder(form) {
})
request.ajaxRequest()
}
function updateCargoTypeInForm(el, type_transport) {
if (!type_transport) return;
getCargoTypesWTypeTransport({
type_transport: type_transport,
owner_type: getFormOwnerType(el),
success_callback: function (res) {
}
})
}

View File

@@ -12,6 +12,6 @@ function chooseRadioInput(el, callback){
let $radio = $parent.querySelector('.radio');
$radio.classList.toggle("checked");
let checked_state = $radio.classList.contains("checked");
if (callback) callback(checked_state)
let el_name = $parent.dataset.name;
if (callback) callback(el, el_name)
}

View File

@@ -2,6 +2,6 @@
{% load i18n %}
<div class="cw_w_radio_inputs_radio_input" data-name="{{ item.0 }}">
<div class="radio{% if item.0 == initial %} checked{% endif %}" onclick="chooseRadioInput(this)"></div>
<div class="radio_label" onclick="chooseRadioInput(this)">{{ item.1 }}</div>
<div class="radio{% if item.0 == initial %} checked{% endif %}" onclick="chooseRadioInput(this, {{ callback }})"></div>
<div class="radio_label" onclick="chooseRadioInput(this, {{ callback }})">{{ item.1 }}</div>
</div>

View File

@@ -1,9 +1,18 @@
{% load static %}
{% load i18n %}
<form name="make_poster_order" class="f_make_poster_order">
{% trans "Укажите город" as placeholder_for_city %}
<form name="make_poster_order" class="f_make_poster_order" data-owner_type="customer">
<div class="form_line">
<div class="field_container" data-type="radio" data-name="type_transport">
{% trans "Обязательно учитывайте Правила и особенности перевозки выбранным Вами видом транспорта" as attention_type_transport %}
<label for="id_cargo_type"><div class="required_field_icon">*</div> {% trans "Каким способом Вы хотите отправить?" %}</label>
{% include 'v2/widgets/w_radio_inputs.html' with name='type_transport' callback='updateCargoTypeInForm' list=form.fields.type_transport.choices initial=form.initial.type_transport %}
{% include 'v2/widgets/w_pay_attention.html' with text=attention_type_transport %}
{% if form.errors.type_transport %}<div class="error_container">{{ form.errors.type_transport.0 }}</div>{% endif %}
</div>
</div>
{% trans "Укажите город" as placeholder_for_city %}
<div class="form_line _50_grid">
<div class="field_container" data-type="location" data-name="from_city">
<label for="id_from_city"><div class="required_field_icon">*</div> {% trans "Откуда забрать посылку" %}</label>
@@ -30,15 +39,6 @@
{% if form.errors.arrival_DT %}<div class="error_container">{{ form.errors.arrival_DT.0 }}</div>{% endif %}
</div>
</div>
<div class="form_line">
<div class="field_container" data-type="radio" data-name="type_transport">
{% trans "Обязательно учитывайте Правила и особенности перевозки выбранным Вами видом транспорта" as attention_type_transport %}
<label for="id_cargo_type"><div class="required_field_icon">*</div> {% trans "Каким способом Вы хотите отправить?" %}</label>
{% include 'v2/widgets/w_radio_inputs.html' with name='type_transport' list=form.fields.type_transport.choices initial=form.initial.type_transport %}
{% include 'v2/widgets/w_pay_attention.html' with text=attention_type_transport %}
{% if form.errors.type_transport %}<div class="error_container">{{ form.errors.type_transport.0 }}</div>{% endif %}
</div>
</div>
<div class="form_line">
<div class="field_container" data-type="input" style="width: 100%" data-name="phone">
{% trans "Если вы оставите это поле пустым - перевозчики смогут только написать вам в личные сообщения на нашем сайте TripWB.com" as attention_phone %}