Checkboxes are not the same height as input boxes - Bootstrap - html

I want the checkboxes on the left side to be the same height as the text input boxes on the right.
HTML:
{% block content %}
<h1>{{ls.name}}</h1>
<form method="post" action="#">
{% csrf_token %}
{% for item in ls.item_set.all %}
<div class="input-group mb-3">
<div class="input-group-prepend">
<div class="input-group-text">
{% if item.complete == True %}
<input type="checkbox", value="clicked", name="c{{item.id}}" checked>
{% else %}
<input type="checkbox", value="clicked", name="c{{item.id}}">
{% endif %}
</div>
</div>
<input type="text", value="{{item.text}}" class="form-control">
</div>
{% endfor %}
<div class="input-group mb-3">
<div class="input-group-prepend">
<button type="submit", name = "newItem", value="newItem" class="btn btn-primary">Add Item</button>
</div>
<input type="text", name="new">
</div>
<button type="submit", name = "save", value="save" class="btn btn-primary">Save</button>
</form>
{% endblock %}

give you check box class then in you linked css give checkbox height and width acc to your need
<div class="input-group-text">
{% if item.complete == True %}
<input class="check" type="checkbox", value="clicked", name="c{{item.id}}" checked>
{% else %}
<input class="check" type="checkbox", value="clicked", name="c{{item.id}}">
{% endif %}
then in your css
.check {
height:20px;
width:20px;
}

Related

HTML page, load 10 items, then wait for scroll and load more

I have a list of so many items that loading them all at the time is very uncomfortable and takes a long time. I would like to implement a script that loads only 10 items and waits for scroll to load more. However I have no idea how to code it.
This is how my page looks:
{% extends "layout.html" %}
{% block content %}
<div class="container">
{% for i in range(data|length) %}
<div class="re-container">
<div class="re-container-item">
<div class="re-item">
<image class="re-img" src="{{url_for('static', filename='img/' + data.UNIQUE_RE_NUMBER[i].replace('/', '-') + '.jpg')}}" onerror="if (this.src != 'static/img/default.jpg') this.src = 'static/img/default.jpg';"></image>
</div>
</div>
<div class="re-container-item">
<div class="re-item">
<p>{{ data.LOCATION[i] }}</p>
<p class="re-date"> {{ data.MIN_DATE[i] }} - {{ data.MAX_DATE[i] }} </p>
</div>
<div class="re-item">
<p>{{ data.ADDRSS[i] }}</p>
</div>
<div class="re-item">
<p><a class="article-title" href="{{url_for('/dashapp/', ure=data.UNIQUE_RE_NUMBER[i])}}">{{data.UNIQUE_RE_NUMBER[i]}}</a></p>
<p class="re-price">{{data.RE_PRICE[i]}}</p>
<hr>
</div>
<div class="re-item">
<p>{{data.RE_INFO[i]}}</p>
</div>
{% if current_user.is_authenticated %}
<div class="re-item">
<form action="{{ url_for('saved') }}" method="POST">
<input type="hidden" value="{{ data.LOCATION[i] }}" name="location">
<input type="hidden" value="{{ data.UNIQUE_RE_NUMBER[i] }}" name="unique">
<input type="hidden" value="{{ data.ADDRSS[i] }}" name="address">
<input type="hidden" value="{{ data.RE_INFO[i] }}" name="info">
<input type="hidden" value="{{ data.RE_HREF[i] }}" name="href">
<input type="hidden" value="{{ data.TYP_ID[i] }}" name="typ">
<input type="hidden" value="{{ data.RE_POLOHA[i] }}" name="poloha">
<input type="hidden" value="{{ data.RE_DRUH[i] }}" name="druh">
<input type="hidden" value="{{ data.RE_TYP[i] }}" name="re-typ">
<input type="hidden" value="" name="dispozice">
<input type="hidden" value="" name="f_druh">
<input type="hidden" value="" name="pplocha">
<input type="hidden" value="" name="plocha">
<input type="hidden" value="" name="l_druh">
<input type="hidden" value="" name="site">
<input type="hidden" value="{{ data.MIN_DATE[i] }}" name="min_d">
<button class="re-button" type="submit">Save</button>
</form>
</div>
{% endif %}
<div class="re-item">
<p>Poloha domu/vily: {{data.RE_POLOHA[i]}}</p>
</div>
<div class="re-item">
<p>Druh domu/vily: {{data.RE_DRUH[i]}}</p>
</div>
<div class="re-item">
<p>Typ domu/vily: {{data.RE_TYP[i]}}</p>
</div>
<div class="re-item">
{% if data.RE_HREF[i] != None %}
More here
{% endif %}
</div>
</div>
</div>
{% endfor %}
</div>
{% endblock content %}
Does anyone have some suggestion?
You can use the loading attribute in HTML. Just like below.
<img src="niceCats.jpg" loading="lazy">
I would advise you to read this aricle that CSSTrick put up on their page. Note this attribute is not supported on any safari version for IOS.

define an element as default value in a list created by a for loop in a django template

here is my html
<div class="modal-body">
<form action="#" id="periodeOptionForm">
<div class=" card-body">
<div class="form-group form-elements">
<div class="form-label">Options</div>
<div class="custom-controls-stacked">
{% for periode in periodes %}
<label class="custom-control custom-radio" id'{{periode.labelle}}'>
<input type="radio" class="custom-control-input" name="example-radios" value="{{periode.valeur}}">
<span class="custom-control-label">{{periode.labelle}} </span>
</label>
{% endfor %}
</div>
</div>
</div>
</form>
</div>
My fbv
def periodes(request):
...
periodes = [{"labelle":"10 minutes","valeur":10},{"labelle":"30 minutes","valeur":30},{"labelle":"1 heure","valeur":60}]
....
return render(request,"my_template.html",{"periodes":periodes}
When I display the html page no elements are selected. I want the first element of my periodes list to be selected by default. How can I do it?
You can use forloop.first around checked:
<input type="radio" class="custom-control-input" name="example-radios" value="{{periode.valeur}}" {% if forloop.first %}checked{% endif %}>

Symfony - pass GET parameters to another route?

I have a table with filters, and i want to download the rows as csv, filtered.
My function to get filters from form:
public function getFilters($request)
{
$filters = [
'stato' => $request->get('stato'),
'cliente' => $request->get('cliente'),
'registrar' => $request->get('registrar'),
'creazione_inizio' => $request->get('creazione_inizio'),
'creazione_fine' => $request->get('creazione_fine'),
'scadenza_inizio' => $request->get('scadenza_inizio'),
'scadenza_fine' => $request->get('scadenza_fine'),
'scadenza_pagamento_inizio' => $request->get('scadenza_pagamento_inizio'),
'scadenza_pagamento_fine' => $request->get('scadenza_pagamento_fine'),
];
return $filters;
}
On the page where the table is i have this code and it works fine:
/**
* #Route("/dashboard", name="dashboard")
*/
public function dashboard(Request $request, PaginatorInterface $paginator): Response
{
$filters = $this->getFilters($request);
}
But on the route to export csv i have this and $filters is always null:
/**
* #Route("/report/report.csv", name="domains_data_csv")
*/
public function exportDomainsDataCsvAction(Request $request)
{
$filters = $this->getFilters($request);
}
I have the filters form and the button to download csv on the dashboard page.
Any tips to make it work?
EDIT
My dashboard page is made like this:
<div class="mb-2">
<span class="h2">Dashboard</span>
</div>
<div class="mb-3">
{{ include('Admin/includes/_search.html.twig') }}
</div>
{{ include('Admin/includes/_filter.html.twig') }}
{% if domains %}
<div class="col-auto">
Scarica CSV
</div>
{{ include('Admin/includes/_domains_table.html.twig',{ 'domains':domains }) }}
{% if is_granted('ROLE_ADMIN') %}
<a class="btn btn-primary" aria-current="page" href="{{path('new_domain')}}" role="button">Nuovo dominio</a>
{% endif %}
{% else %}
{% endif %}
Filters form:
<div class="card">
<div class="row align-items-center">
<a class="text-decoration-none text-reset" id="filter-header" href="#collapseExample" data-bs-toggle="collapse" aria-expanded="false">
<div class="card-header d-flex align-items-center">
<h5 class="pe-3">Filtri</h5>
<div class="border-1 bg-success border border-success w-100" style="opacity:unset;"></div>
<i class="bi bi-chevron-right ps-3 fs-3 text-success arrow"></i>
</div>
</a>
</div>
<div class="collapse" id="collapseExample">
<div class="card-body">
<form id="form-filter-status" method="GET">
{% if is_granted('ROLE_ADMIN') %}
<div class="row mb-3 justify-content-center">
<div class="card col-sm-3 mx-3">
<div class="card-body">
<div class="card-title">Stato:</div>
<div class="col-sm">
<select name="stato" class="form-select" onchange='this.form.submit();'>
<option value="" {% if filters.stato is empty %} selected {% endif %}>Seleziona...</option>
<option value="1" {% if filters.stato == 1 %} selected {% endif %}>Attivo</option>
<option value="2" {% if filters.stato == 2 %} selected {% endif %}>Richiesta Dismissione</option>
<option value="3" {% if filters.stato == 3 %} selected {% endif %}>Dismesso</option>
<option value="4" {% if filters.stato == 4 %} selected {% endif %}>Richiesto Trasferimento</option>
<option value="5" {% if filters.stato == 5 %} selected {% endif %}>Trasferito</option>
</select>
</div>
</div>
</div>
<div class="card col-sm-3 mx-3">
<div class="card-body">
<div class="card-title">Cliente:</div>
<div class="col-sm">
<select name="cliente" class="form-select" onchange='this.form.submit();'>
<option value="" {% if filters.cliente is empty %} selected {% endif %}>Seleziona...</option>
<option value="1" {% if filters.cliente == 1 %} selected {% endif %}>KINETIKON s.r.l.</option>
<option value="2" {% if filters.cliente == 2 %} selected {% endif %}>CINQUEBIT s.r.l.</option>
<option value="3" {% if filters.cliente == 3 %} selected {% endif %}>JAKALA S.p.A.</option>
<option value="4" {% if filters.cliente == 4 %} selected {% endif %}>IN.SI. s.r.l.</option>
<option value="5" {% if filters.cliente == 5 %} selected {% endif %}>PAGNOSSIN s.r.l.</option>
<option value="6" {% if filters.cliente == 6 %} selected {% endif %}>ELEPHASE s.r.l.</option>
</select>
</div>
</div>
</div>
<div class="card col-sm-3 mx-3">
<div class="card-body">
<div class="card-title">Register:</div>
<div class="col-sm">
<select name="registrar" class="form-select" onchange='this.form.submit();'>
<option value="" {% if filters.registrar is empty %} selected {% endif %}>Seleziona...</option>
<option value="1" {% if filters.registrar == 1 %} selected {% endif %}>Register</option>
<option value="2" {% if filters.registrar == 2 %} selected {% endif %}>OpenProvider</option>
<option value="3" {% if filters.registrar == 3 %} selected {% endif %}>TowerTech</option>
<option value="4" {% if filters.registrar == 4 %} selected {% endif %}>Aruba</option>
<option value="5" {% if filters.registrar == 5 %} selected {% endif %}>Aruba Business</option>
</select>
</div>
</div>
</div>
</div>
{% endif %}
<div class="row justify-content-center">
<div class="card col-sm-3 mx-3">
<div class="card-body">
<div class="card-title">Creazione</div>
<div class="input-group mb-3">
<span class="input-group-text col-2" id="creazione_inizio">Da:</span>
<input type="date" name="creazione_inizio" class="form-control" value="{{filters.creazione_inizio}}" placeholder="Creazione inizio" aria-label="Creazione inizio" aria-describedby="creazione_inizio">
</div>
<div class="input-group mb-3">
<span class="input-group-text col-2" id="creazione_fine">A:</span>
<input type="date" name="creazione_fine" class="form-control" value="{{filters.creazione_fine}}" placeholder="Creazione fine" aria-label="Creazione fine" aria-describedby="creazione_fine">
</div>
<div class="d-grid gap-2">
<button class="btn btn-outline-success" type="submit">Filtra data creazione</button>
</div>
</div>
</div>
<div class="card col-sm-3 mx-3">
<div class="card-body">
<div class="card-title">Scadenza</div>
<div class="input-group mb-3">
<span class="input-group-text col-2" id="scadenza_inizio">Da:</span>
<input type="date" name="scadenza_inizio" class="form-control" value="{{filters.scadenza_inizio}}" placeholder="Scadenza inizio" aria-label="Scadenza inizio" aria-describedby="scadenza_inizio">
</div>
<div class="input-group mb-3">
<span class="input-group-text col-2" id="scadenza_fine">A:</span>
<input type="date" name="scadenza_fine" class="form-control" value="{{filters.scadenza_fine}}" placeholder="Scadenza fine" aria-label="Scadenza fine" aria-describedby="scadenza_fine">
</div>
<div class="d-grid gap-2">
<button class="btn btn-outline-success" type="submit">Filtra data scadenza</button>
</div>
</div>
</div>
<div class="card col-sm-3 mx-3">
<div class="card-body">
<div class="card-title">Scadenza pagamento</div>
<div class="input-group mb-3">
<span class="input-group-text col-2" id="scadenza_pagamento_inizio">Da:</span>
<input type="date" name="scadenza_pagamento_inizio" class="form-control" value="{{filters.scadenza_pagamento_inizio}}" placeholder="Scadenza pagamento inizio" aria-label="Scadenza pagamento inizio" aria-describedby="scadenza_pagamento_inizio">
</div>
<div class="input-group mb-3">
<span class="input-group-text col-2" id="scadenza_pagamento_fine">Da:</span>
<input type="date" name="scadenza_pagamento_fine" class="form-control" value="{{filters.scadenza_pagamento_fine}}" placeholder="Scadenza pagamento fine" aria-label="Scadenza pagamento fine" aria-describedby="scadenza_pagamento_fine">
</div>
<div class="d-grid gap-2">
<button class="btn btn-outline-success" type="submit">Filtra data scadenza pagamento</button>
</div>
</div>
</div>
</div>
{% if query is defined %}
<input type="hidden" name="query" value="{{query}}">
{% endif %}
</form>
</div>
</div>
To pass the current GET parameters (from URL, not form) You should be able to modify the href as follows:
Scarica CSV
To use the current form values you need to use JavaScript to set the form's action attribute value to that returned by {{ path('domains_data_csv') }} and submit the form.

How to put two password fields in a row at UserCreationForm of Django, or how to add my own html in UserCreationForm?

I created a sign up form by extending Django's UserCreationForm. Since Django adds all HTMLs by default I can't put my own HTML in it, just to customize it a bit.
This is how my current signup form looks like:
you can see password and password confirmation are added one after another. I would like to show them side by side, something like this:
I don't know where to add my HTML to make it look like the one above, this is my signup.html here:
{% block content %}
<form action="." method="POST" class="signup">
<h4 class="display-6 bg-secondary text-white p-3">Create your account</h4>
{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="Sign up" class="btn btn-primary btn-block">
<p class="display-6 bg-signup p-3">Have an account Sign In</p>
</form>
{% endblock content %}
No one answered my question within last 36 hours. Finally just now I find an answer to my own question. So I am answering my own question, maybe someone in the future read it and find it useful.
After adding my custom HTML and CSS I finally manage to show two password fields side by side like this:
I used django-widget-tweaks to achieve this result:
as you can see in above picture, two password fields are added side by side. Moreover, errors are shown as well.
this was the previous html form:
{% block content %}
<form action="." method="POST" class="signup">
<h4 class="display-6 bg-secondary text-white p-3">Create your account</h4>
{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="Sign up" class="btn btn-primary btn-block">
<p class="display-6 bg-signup p-3">Have an account Sign In</p>
</form>
{% endblock content %}
Now the HTML codes look like this one below, the code pretty much explains itself. So I don't feel to elaborate it. I used bootstrap 4.
{% block content %}
<div class="accountform">
<form method="POST">
<h4 class="display-6 text-white p-3">Create your account</h4>
{% csrf_token %}
<div class="alert alert-danger p-0" style="border:none;">
{% for field in form.visible_fields %}
{% for error in field.errors %}
<span class="err">{{ error }}</span><br>
{% endfor %}
{% endfor %}
</div>
<div class="form-group">
<label for="id_username">Username</label>
{% render_field form.username class='form-control' placeholder='John Doe' %}
</div>
<div class="form-group">
<label for="id_email">Email</label>
{% render_field form.email class='form-control' placeholder='johndoe#email.com' %}
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="id_password1">Password</label>
{% render_field form.password1 class='form-control' placeholder='****' %}
</div>
<div class="form-group col-md-6">
<label for="id_password2">Confirm Password</label>
{% render_field form.password2 class='form-control' placeholder='****' %}
</div>
</div>
<input type="submit" value="Sign up" class="btn btn-primary btn-block">
<p class="display-6 bg-signup p-3">Have an account Sign In</p>
</form>
</div>
</div>
{% endblock content %}
dont' forget to add {% load widget_tweaks %} at the top of your template.
Thanks

Bootstrap misaligned label under textarea

I have a bootstrap form which consists of basic input fields and a few textarea's. Im using Django for my form validation and am having a persistent problem aligning validation labels under the textarea's. This form is only using bootstrap css modules so there is no custom css interfering with it as far as i can tell.
Example: The date and time field align perfectly as the notes validation label does not.
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="well well-lg">
<form class="form-horizontal" action="" autocomplete="off" method="post">
{% csrf_token %}
{% for field in UserForm %}
<div class="form-group">
<label class="col-md-4 control-label" for="{{ field.label }}"> {{ field.label }}</label>
<div class="col-md-6">
{{ field }}
</div>
{% for error in field.errors %}
<div class="col-md-6">
<strong>{{ error|escape }}</strong>
</div>
{% endfor %}
</div>
{% endfor %}
</form>
</div>
</div>
</div>
The number of columns inside the class="row" does not add up to 12. Try rewriting the form-group part like this:
<div class="form-group">
<label class="col-md-4 control-label" for="{{ field.label }}"> {{ field.label }}</label>
<div class="col-md-6">
{{ field }}
{% for error in field.errors %}
<p>
<strong>{{ error|escape }}</strong>
</p>
{% endfor %}
</div>
</div>