I'm trying to set up a language selector using the Framework Django.
I used this code:
<form action="/i18n/setlang/" method="post">
{% csrf_token %}
<input name="next" type="hidden" value=""/>
<select class="select-style" name="language" onchange="this.form.submit();" style="width:100px">
{% for lang in LANGUAGES %}
<option value="{{ lang.0 }}" {% if lang.0 == LANGUAGE_CODE %} selected="selected"{% endif %}>{{ lang.1 }}</option>
{% endfor %}
</select>
</form>
It works well with Chrome and Safari but not Firefox.
The 1st language (English) is not displayed in the drop-down menu.
/ setting.py /
LANGUAGES = (
('en', gettext('English')),
('fr', gettext('French')),
('nl', gettext('Dutch')),
('it', gettext('Italian')),
('es', gettext('Spanish')),
('th', gettext('Thai')),
)
Thanks
EDIT
I've finally fixed my problem adding a selected=selected field option which is displayed only in Chrome and Safari but at least all languages are displayed in FF.
<form action="/i18n/setlang/" method="post">
{% csrf_token %}
<input name="next" type="hidden" value=""/>
<select class="select-style" name="language" onchange="this.form.submit();" style="width:100px;font-size:12px;">
<option selected="selected" disabled="disabled">Select your language</option>
{% for lang in LANGUAGES %}
<option value="{{ lang.0 }}" {% if lang.0 == LANGUAGE_CODE %} selected="selected"{% endif %}>{{lang.1|title}}</option>
{% endfor %}
</select>
</form>
Related
So I have a bundle I created to add two products to cart once those products are selected. I want them to be added to cart at the same time. I'm currently only getting one product being added, with the name="id". How can I create the values in input for both to checkout?
Here's my form:
<form method="post" action="/cart/add" class="col-button ">
<input id="idPrice" type="hidden" name="id" value="" />
<input id="designPrice" type="hidden" name="id" value="" />
<input min="1" max="2" type="hidden" id="quantity" name="quantity" />
<button name="checkout" {%unless product.available %}style='margin-bottom:20px;'{% endunless %}type="{% if settings.cart_action == 'ajax' %}button{% else %}submit{% endif %}" name="add" class="collection-add-to-cart {% if settings.cart_action == 'ajax' %} ajax-submit {% endif %}action_button add_to_cart {% if show_payment_button %} action_button--secondary {% endif %} {% if product.available == false %}disabled{% endif %}" data-label={{ add_to_cart_label | json }}>
{{ 'layout.general.checkout' | t }}
</button>
</form>
Thanks in advance!
Hello I have the following code :
<select name="test1" class="form-control">
<option value=""></option>
{% for test in tests %}
<option value="{{ test.id }}">{{ test.name }}</option>
{% endfor %}
</select>
Then I want to do something like this ;
{% if test.id %}
# show something but I need to know if there is sometinh in test.id
# I think the problem comes from this line, in fact I want this condition is realised if test.id is not empty else the condition is not realised.
{% endif %}
How can I do this ?
See if this approach can help.
<select name="test1" class="form-control">
<option value=""></option>
{% for test in tests %}
<option value="{{ test.id }}">{{ test.name }}</option>
{% if test.id %}
#show what you want..
{% empty %} <<<<======
#if empty do this...
{% endif %}
{% endfor %}
</select>
Just an example:
import Http Response from django
from django.shortcuts import render
#create a function
def your_view(request):
# create a dictionary
context = {
#enter code here
"data" : [],
}
# return response
return render(request, "template.html", context)
Now in templates/template.html,
{% for i in data %}
<div class="row">
{{ i }}
</div>
{% empty %}
<h4>There is nothing in this list</h4>
{% endfor %}
You can have a better look at this link:
https://www.geeksforgeeks.org/for-empty-loop-django-template-tags/
I have two drop down list inputs ,both of them comes from datalist , i want that base on the input that the user choose, to filter the other input to show only relevant results .
I am rendering the data from python back to HTML page
The data contains company name and bank account number,
So i want base on the company that user choose to show only the relevant account to the selected company
<form id="the_form" method="POST">
{% csrf_token %}
From:
<input name="start_date" class="datepicker" type="date" value={{start_date}}/>
To:
<input name="end_date" class="datepicker" type="date" value={{end_date}}/>
<input type="text" list='List_of_Companies' data-search-in="Company" id="Input1" name="Companyname" placeholder="Choose a Company" value="{{ Company}}"/>
<input type="text" list='List_of_Accounts' data-search-in="Account" id="Input2" name="Accountname" placeholder="Choose an Account ID" value="{{ Account_Id}}"/>
<br> <br>
<button name="action" type="submit" id="showccounts" value="show">Show</button>
<button name="action" type="submit" value="download">Download</button>
<datalist id="List_of_Companies">
<select id="filenamelist" size="5" class="select">
{% for Company in info_list %}
<option value="{{ Company.3 }}">{{ Company.3 }}</option>
{% endfor %}
</select>
</datalist>
<datalist id="List_of_Accounts">
<select id="filenamelist" size="5" class="select">
{% for Company in info_list %}
<option value="{{ Company.0 }}">{{ Company.3 }}</option>
{% endfor %}
</select>
</datalist>
</form>
{% load staticfiles %}
<div id="loading" style="width:300px;height:300px;display:table-cell; vertical-align:middle; text-align:center">
<img src="{% static "app/images/Loading_icon.gif" %}" style="margin:auto">
</div>
<table id="theTable" hidden>
<thead>
<tr>
{% for c in columns %}
<th>{{ c }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for r in rows %}
<tr>
{% for c in r %}
<td>{{ c }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
{% block scripts %}
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
Hello I have this code using Django in a HTML file :
<select class="form-control" data-formsource="test" id="id_test1" name="type">
{% for x,y in opt %}
<option value="{{ y }}" data-select="{{ y }}">{% trans y %}</option>
{% endfor %}
</select>
And there is an option which is "available" but I don't want to see this option ... How can I do this ?
Thank you very much !
<select class="form-control" data-formsource="test" id="id_test1" name="type">
{% for x,y in opt %}
{% if x != 'available' %}
<option value="{{ y }}" data-select="{{ y }}">{% trans y %}</option>
{% endif %}
{% endfor %}
</select>
Currently I'm trying to get Shopify's cart.js to add my products to cart.
It used to work perfectly but when I added variants it's started to break and for the life of me I can't get it to work. When clicking the button - it doesn't add the product to the bag at all.
<form action="/cart/add" method="post" data-cart-submit>
{% if product.variants.size > 1 %}
<div class="w-form">
<div class="inpost-form-option w-clearfix">
<label class="inpost-form-label">{{ product.options.first }}</label>
<select id="variant-select" class="inpost-quantity w-select">
{% for variant in product.variants %}
{% if variant.available == true %}
<option value="{{ variant.id }}">{{ variant.title }}</option>
{% endif %}
{% endfor %}
</select>
</div>
</div>
{% endif %}
<button class="inpost-buy w-button" type="submit" data-cart-add="{{ variant.id }}">Add to Bag →</button>
</form>
Added Javascript
<script type="text/javascript">
jQuery(function() {
CartJS.init({{ cart | json }});
});
</script>
Console Error
shop_events_listener-91b4691….js:1 POST
https://monah-uk.myshopify.com/cart/add.js 404 (Not Found)