fix form new route
This commit is contained in:
SDE
2023-07-28 19:07:36 +03:00
parent 45234121d4
commit c0ed5d5803
4 changed files with 259 additions and 177 deletions

View File

@@ -19,10 +19,19 @@ def new_route_view_ajax(request):
if request.method != 'POST':
raise Http404
data = request.POST
form = CreateRouteForm(data)
if not form.is_valid():
pass
Dict = {
'form': CreateRouteForm()
'form': form
}
# print(form)
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
return JsonResponse({'html': html}, status=200)

View File

@@ -3,10 +3,11 @@ from django.utils.translation import gettext_lazy as _
from BaseModels.base_models import BaseModel
type_transport_choices = (
type_transport_choices = [
('', _('-- Выберите cпособ перевозки --')),
('avia', _('Авиатранспорт')),
('road', _('Наземный транспорт'))
)
]
transfer_location_choices = (
('airport', _('В аэропорту')),
@@ -35,7 +36,7 @@ class Route(BaseModel):
choices=owner_type_choices, default='customer', verbose_name=_('Тип опреации'))
type_transport = models.CharField(
choices=type_transport_choices, default='avia', verbose_name=_('Выберите способ перевозки'))
choices=type_transport_choices, default='', verbose_name=_('Выберите способ перевозки'))
departure_DT = models.DateTimeField(default=True, verbose_name=_('Дата и время выезда'))
arrival_DT = models.DateTimeField(default=True, verbose_name=_('Дата и время прибытия'))
from_address_point = models.IntegerField(verbose_name=_('Пункт выезда'))

View File

@@ -42,8 +42,11 @@ function sendRoute(el){
//cleaning route inputs after selection changes
function OnSelectionChange(el) {
event.preventDefault()
let form = el.form;
let formData = new FormData(form);
$.ajax({
headers: {"X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val()},
url: '/ru/user_account/new_route_view/',
@@ -55,23 +58,21 @@ function OnSelectionChange(el) {
// enctype: 'json',
data: formData,
success: function (data) {
// console.log('data received')
console.log('data.html');
// location.href = '/profile'
document.querySelector(".info_profile").innerHTML = data.html
$(document).ready(function (e){
$('#id_weight').ionRangeSlider({
skin: "round",
type: "single",
min: 0,
max: 1000,
from: 100,
step: 1,
grid: true,
grid_num: 5,
});
});
//
// $(document).ready(function (e){
// $('#id_weight').ionRangeSlider({
// skin: "round",
// type: "single",
// min: 0,
// max: 1000,
// from: 100,
// step: 1,
// grid: true,
// grid_num: 5,
// }
//get dynamic value
// let fromCountry = document.getElementById('id_from_country');

View File

@@ -9,14 +9,18 @@
<label for="id_type_transport">{{ form.fields.type_transport.label }}</label>
</div>
<div>
<select
onchange="OnSelectionChange(this)"
name="type_transport"
id="id_type_transport">
{% for item in form.fields.type_transport.choices %}
<option
value="{{ item.0 }}"{% if form.cleaned_data.type_transport == item.0 %}
selected="selected"{% endif %}>{{ item.1 }}
value="{{ item.0 }}"
{% if form.cleaned_data.type_transport == item.0 %}
selected="selected"
{% endif %}>
{{ item.1 }}
</option>
{% endfor %}
</select>
@@ -25,6 +29,7 @@
{% endif %}
</div>
{% if form.cleaned_data and form.cleaned_data.type_transport and form.cleaned_data.type_transport != '' %}
<hr>
<div class="departure_arrival">
<div>
@@ -57,6 +62,58 @@
{% endif %}
</div>
</div>
<hr>
<div class="from_to_country">
<div class="from_country_container">
<label for="id_from_address_point">{{ form.fields.from_address_point.label }}</label>
<input type="number" name="from_address_point" id="id_from_address_point" hidden />
<input
oninput="searchTown(this)"
onclick="searchTown(this)"
onblur="onblurInputField(event, this)"
type="text"
name="from_address_point_txt"
{% if form.fields.from_address_point.required %} required{% endif %}
id="id_from_address_point_txt"
{% if form.cleaned_data.from_address_point_txt %}value="{{ form.cleaned_data.from_address_point_txt }}"{% endif %}
/>
<div class="input_list" name="from_address_point_txt_list">
</div>
{% if form.errors and form.errors.from_address_point %}
<span>{{ form.errors.from_address_point}}</span>
{% endif %}
</div>
<div>
<label for="id_to_address_point">{{ form.fields.to_address_point.label }}</label>
<input type="number" name="to_address_point" id="id_to_address_point" hidden />
<input
oninput="searchTown(this)"
onclick="searchTown(this)"
onblur="onblurInputField(event, this)"
type="text"
name="to_address_point_txt"
{% if form.fields.to_address_point.required %} required{% endif %}
id="id_to_address_point_txt"
{% if form.cleaned_data.to_address_point_txt %}value="{{ form.cleaned_data.to_address_point_txt}}"{% endif %}
{% if form.errors and form.errors.departure_DT %}
<span>{{ form.errors.departure_DT }}</span>
{% endif %}
</div>
<div>
<label for="id_arrival_DT">{{ form.fields.arrival_DT.label }}</label>
<input
type="datetime-local"
name="arrival_DT"
{% if form.fields.arrival_DT.required %} required{% endif %}
id="id_arrival_DT"
{% if form.data.arrival_DT %}value="{{ form.data.arrival_DT }}"{% endif %}
{# |date: 'Y-m-d H:i' #}
/>
{% if form.errors and form.errors.arrival_DT %}
<span>{{ form.errors.arrival_DT }}</span>
{% endif %}
</div>
</div>
<hr>
<div class="from_to_country">
<div class="from_country_container">
@@ -168,6 +225,17 @@
{# </div>#}
<div>
{% for item in form.fields.cargo_type.choices %}
<input
type="checkbox"
name="cargo_type"
id="id_cargo_type"
{% if form.fields.cargo_type.required %} required{% endif %}
value="{{ item.0 }}"
{% if form.fields.cargo_type == item.0 %}
{% endif %}/>{{ item.1 }}
{% endfor %}
<div class="checkbox_cargo_type">
{% for item in form.fields.cargo_type.choices %}
<input
@@ -254,4 +322,7 @@
<button id="registration" onclick="sendRoute(this)"> Разместить объявления </button>
</div>
{% endif %}
</form>