Wysihtml5 brokes modal - bootstrap-modal

If i use wysihtml5 in modal, when i open modal with form that use wyshtml5 it works fine first time. But when i close modal, and then open it second time then wysihtml5 funtionality not working it shows only text area not toolbox and iframe. if i close the model and it open again it working file as first time. and fourth time same issue arise.in other word wysihtml5 working alternatively in bootstrap modal.It's wysihtml5 bug, or i`m doing something bad?
$(document).ready(function(e) {
$('#description').wysihtml5();
});
<div class="modal-body">
<div class="alert alert-danger error_block" style="display: none"></div>
<form action="#" id="post_updt" novalidate="novalidate" enctype="multipart/form-data">
<div class="row">
<div class="col-md-8">
<div class="form-group">
<label class="control-label">
<h4>Title <span class="required" aria-required="true">* </span></h4>
</label>
<div class="controls">
<input type="text" placeholder="Post Title" id="post_title" name="post_title" class="col-md-12 form-control" required="true" value="">
</div><label id="post_title-error" class="help-block help-block-error" for="post_title"></label>
</div>
</div>
<div class="form-group post_description">
<label class="control-label">
<h4>Description</h4>
</label>
<div class="controls">
<textarea id="description" name="description" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
</div>
</div>
<div class="form-group event_dates hide">
<label class="control-label">
<h4>Event Dates <span class="required" aria-required="true">* </span></h4>
</label>
<div class="controls">
<input type="text" placeholder="Event Dates" id="event_dates" name="event_dates" class="col-md-12 form-control">
</div>
</div>
</form>
$(document).ready(function(e) {
$("#post_type").change();
$('#description').wysihtml5();
});
$("#post_type").on('change', function () {
var vl = $(this).val();
$("#file_url").removeAttr("required");
if (vl == 'Event') {
$(".event_dates").removeClass("hide");
$(".upld_document,.post_description").addClass("hide");
} else if (vl == 'Document') {
if($("#old_file").val()==""){
$("#file_url").attr("required","true");
}
$(".upld_document").removeClass("hide");
$(".post_description,.event_dates").addClass("hide");
} else {
$(".upld_document,.post_description").removeClass("hide");
$(".event_dates").addClass("hide");
}
});

Yes, there is a bug. When you use wysihtml5 in modal, you should initialize it on modal shown and you should remove it on modal disappear.
jQuery(document).ready(function () {
$('#modal_Event').on('shown', function () {
$('#description').wysihtml5();
});
$('#modal_Event').on('hidden', function () {
$('.wysihtml5-sandbox, .wysihtml5-toolbar').remove();
$('#description').show();//optional
});
});

Related

How to read additional data posted by form in django forms.py

I'm trying to write kind off bussiness mail management.
In simple world, it'll have bunch of mail templates that will use un mailmerge operation
There will be 2 kind of user:
those who create mail templates, let's call them 'tc' (template creator)
thoise who will issueing mails by term of triggering a mail merge.
In this post I will only ask about the tc part.
The work sequnce will :
TC make a MS docx,
upload to this web app
web app will get all variable names from docx ( I use docxtpl library), and save it on MailTemplate model class.
here is my MailTemplate model class
class MailTemplate(models.Model):
name = models.CharField(max_length=20)
tfile = models.FileField(upload_to='uploads/mailtemplate', null=True, blank=True)
schema = models.CharField(max_length=256, blank=True, null=True, editable=False)
# conto: ['{"name": "kepada", "label": "Kepada", "type": 2, "format": ""}']
def __str__(self) -> str:
return self.name
all variables gathered by docxtpl, is combined in the form as list-of-dicts and saved in MailTemplate.schema
example:
[{"name": "date", "label": null, "type": 2, "format": ""}, {"name": "invoiceNumber", "label": null, "type": 2, "format": ""}, {"name": "company", "label": null, "type": 2, "format": ""}, {"name": "total", "label": null, "type": 2, "format": ""}]
When TC first update new template, MailTemplate.schema is still empty.
I make ModelAdmin to use custom change_view template.
class MailTemplateAdmin(admin.ModelAdmin):
change_form_template = 'mailtemplate_form.html'
form = MailTemplateForm
and here is the mailtemplate_form.html
{% extends "admin/change_form.html" %}
{% block after_field_sets %}
<!--- add htmx -->
<script src="https://unpkg.com/htmx.org#1.6.0"></script>
<style>
/* DivTable.com */
.divTable{
display: table;
width: 100%;
}
.divTableRow {
display: table-row;
}
.divTableCell, .divTableHead {
border: 1px solid #999999;
display: table-cell;
padding: 3px 10px;
}
.divTableHeading {
display: table-header-group;
font-weight: bold;
}
.divTableFoot {
background-color: #EEE;
display: table-footer-group;
font-weight: bold;
}
.divTableBody {
display: table-row-group;
}
</style>
<style>
.button.bino_btn {
background:none; border:none;
}
</style>
{% if not add %}
<div id="schema_head" hx-get="{% url 'get_schema' object_id %}" hx-trigger="load" hx-target="#alldata" hx-swap="innerHTML">
<b>Schema </b>
<button class="button.bino_btn" hx-get="{% url 'get_schema' object_id %}" hx-trigger="click" hx-target="#alldata" hx-swap="innerHTML">Refresh</button>
</div>
<div id="table_for_schema" class="divTable">
<div class="divTableHeading">
<div class="divTableRow">
<div class="divTableHead">Nama Variabel</div>
<div class="divTableHead">Label</div>
<div class="divTableHead">Tipe</div>
<div class="divTableHead">Format</div>
</div>
</div>
<div id="alldata" class="divTableBody">
</div>
</div>
{% endif %}
{% endblock %}
when that template called in 'change' mode, it will call a views function that will read respective MailTemplate.schema, deserialized it and add additional fields inside form.
Here is resulted HTML form (copied from 'inspector') :
<html dir="ltr" lang="en-us"><head>
<title>docx01 | Change mail template | Django site admin</title>
<link rel="stylesheet" href="/static/admin/css/base.css">
<link rel="stylesheet" href="/static/admin/css/dark_mode.css">
<link rel="stylesheet" href="/static/admin/css/nav_sidebar.css">
<script src="/static/admin/js/nav_sidebar.js" defer=""></script>
<link rel="stylesheet" href="/static/admin/css/forms.css">
<script src="/admin/jsi18n/"></script>
<script src="/static/admin/js/vendor/jquery/jquery.js"></script>
<script src="/static/admin/js/jquery.init.js"></script>
<script src="/static/admin/js/core.js"></script>
<script src="/static/admin/js/admin/RelatedObjectLookups.js"></script>
<script src="/static/admin/js/actions.js"></script>
<script src="/static/admin/js/urlify.js"></script>
<script src="/static/admin/js/prepopulate.js"></script>
<script src="/static/admin/js/vendor/xregexp/xregexp.js"></script>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" href="/static/admin/css/responsive.css">
<meta name="robots" content="NONE,NOARCHIVE">
<style> .htmx-indicator{opacity:0;transition: opacity 200ms ease-in;} .htmx-request .htmx-indicator{opacity:1} .htmx-request.htmx-indicator{opacity:1} </style></head>
<body class=" app-myapp model-mailtemplate change-form" data-admin-utc-offset="0">
<!-- Container -->
<div id="container">
<!-- Header -->
<div id="header">
<div id="branding">
<h1 id="site-name">Django administration</h1>
</div>
<div id="user-tools">
Welcome,
<strong>admin</strong>.
View site /
Change password /
<form id="logout-form" method="post" action="/admin/logout/">
<input type="hidden" name="csrfmiddlewaretoken" value="ZBziDfqR44MaX5oT5fyG9cRUkO1uqi70JZjLQB1gzdHWHaL2l7gNYJH0HnLaMWtp">
<button type="submit">Log out</button>
</form>
</div>
</div>
<!-- END Header -->
<div class="breadcrumbs">
Home
› Myapp
› Mail templates
› docx01
</div>
<div class="main shifted" id="main">
<button class="sticky toggle-nav-sidebar" id="toggle-nav-sidebar" aria-label="Toggle navigation"></button>
<nav class="sticky" id="nav-sidebar">
<input type="search" id="nav-filter" placeholder="Start typing to filter…" aria-label="Filter navigation items">
<div class="app-auth module">
<table>
<caption>
Authentication and Authorization
</caption>
<tbody><tr class="model-group">
<th scope="row">Groups</th>
<td>Add</td>
</tr>
<tr class="model-user">
<th scope="row">Users</th>
<td>Add</td>
</tr>
</tbody></table>
</div>
<div class="app-myapp module current-app">
<table>
<caption>
Myapp
</caption>
<tbody><tr class="model-mailtemplate current-model">
<th scope="row">Mail templates</th>
<td>Add</td>
</tr>
</tbody></table>
</div>
</nav>
<div class="content">
<!-- Content -->
<div id="content" class="colM">
<h1>Change mail template</h1>
<h2>docx01</h2>
<div id="content-main">
<ul class="object-tools">
<li>
History
</li>
</ul>
<form enctype="multipart/form-data" method="post" id="mailtemplate_form" novalidate=""><input type="hidden" name="csrfmiddlewaretoken" value="ZBziDfqR44MaX5oT5fyG9cRUkO1uqi70JZjLQB1gzdHWHaL2l7gNYJH0HnLaMWtp">
<div>
<fieldset class="module aligned ">
<div class="form-row field-name">
<div>
<label class="required" for="id_name">Name:</label>
<input type="text" name="name" value="docx01" class="vTextField" maxlength="20" required="" id="id_name">
</div>
</div>
<div class="form-row field-tfile">
<div>
<label for="id_tfile">Tfile:</label>
<p class="file-upload">Currently: uploads/mailtemplate/invoice-template_BCpUuSw.docx
<span class="clearable-file-input">
<input type="checkbox" name="tfile-clear" id="tfile-clear_id">
<label for="tfile-clear_id">Clear</label></span><br>
Change:
<input type="file" name="tfile" id="id_tfile"></p>
</div>
</div>
</fieldset>
<!--- add htmx -->
<script src="https://unpkg.com/htmx.org#1.6.0"></script>
<style>
/* DivTable.com */
.divTable{
display: table;
width: 100%;
}
.divTableRow {
display: table-row;
}
.divTableCell, .divTableHead {
border: 1px solid #999999;
display: table-cell;
padding: 3px 10px;
}
.divTableHeading {
display: table-header-group;
font-weight: bold;
}
.divTableFoot {
background-color: #EEE;
display: table-footer-group;
font-weight: bold;
}
.divTableBody {
display: table-row-group;
}
</style>
<style>
.button.bino_btn {
background:none; border:none;
}
</style>
<div id="schema_head" hx-get="/mst/htmx/get_schema/7" hx-trigger="load" hx-target="#alldata" hx-swap="innerHTML" class="">
<b>Schema </b>
<button class="button.bino_btn" hx-get="/mst/htmx/get_schema/7" hx-trigger="click" hx-target="#alldata" hx-swap="innerHTML">Refresh</button>
</div>
<div id="table_for_schema" class="divTable">
<div class="divTableHeading">
<div class="divTableRow">
<div class="divTableHead">Nama Variabel</div>
<div class="divTableHead">Label</div>
<div class="divTableHead">Tipe</div>
<div class="divTableHead">Format</div>
</div>
</div>
<div id="alldata" class="divTableBody"><div id="31d6fa45-e660-4983-bfcb-f5217fd26e16" class="divTableRow">
<div class="divTableCell">
<input type="hidden" name="varname_31d6fa45-e660-4983-bfcb-f5217fd26e16" value="date">
date
</div>
<div class="divTableCell">
<input type="text" name="varlabel_31d6fa45-e660-4983-bfcb-f5217fd26e16" value="None" class="vTextField" maxlength="20">
</div>
<div class="divTableCell">
<select name="vartype_31d6fa45-e660-4983-bfcb-f5217fd26e16">
<option value="1">
Integer</option>
<option value="2" selected="">
String</option>
<option value="3">
Date</option>
</select>
</div>
<div class="divTableCell">
<input type="text" name="varformat_31d6fa45-e660-4983-bfcb-f5217fd26e16" class="vTextField" maxlength="20">
</div>
</div>
<div id="0bffd751-79a3-4561-b62f-dc254e2bbaac" class="divTableRow">
<div class="divTableCell">
<input type="hidden" name="varname_0bffd751-79a3-4561-b62f-dc254e2bbaac" value="invoiceNumber">
invoiceNumber
</div>
<div class="divTableCell">
<input type="text" name="varlabel_0bffd751-79a3-4561-b62f-dc254e2bbaac" value="None" class="vTextField" maxlength="20">
</div>
<div class="divTableCell">
<select name="vartype_0bffd751-79a3-4561-b62f-dc254e2bbaac">
<option value="1">
Integer</option>
<option value="2" selected="">
String</option>
<option value="3">
Date</option>
</select>
</div>
<div class="divTableCell">
<input type="text" name="varformat_0bffd751-79a3-4561-b62f-dc254e2bbaac" class="vTextField" maxlength="20">
</div>
</div>
<div id="cc528860-3855-4645-bd3f-948e297bda76" class="divTableRow">
<div class="divTableCell">
<input type="hidden" name="varname_cc528860-3855-4645-bd3f-948e297bda76" value="company">
company
</div>
<div class="divTableCell">
<input type="text" name="varlabel_cc528860-3855-4645-bd3f-948e297bda76" value="None" class="vTextField" maxlength="20">
</div>
<div class="divTableCell">
<select name="vartype_cc528860-3855-4645-bd3f-948e297bda76">
<option value="1">
Integer</option>
<option value="2" selected="">
String</option>
<option value="3">
Date</option>
</select>
</div>
<div class="divTableCell">
<input type="text" name="varformat_cc528860-3855-4645-bd3f-948e297bda76" class="vTextField" maxlength="20">
</div>
</div>
<div id="66971274-8d70-4766-8254-996bda8991b0" class="divTableRow">
<div class="divTableCell">
<input type="hidden" name="varname_66971274-8d70-4766-8254-996bda8991b0" value="total">
total
</div>
<div class="divTableCell">
<input type="text" name="varlabel_66971274-8d70-4766-8254-996bda8991b0" value="None" class="vTextField" maxlength="20">
</div>
<div class="divTableCell">
<select name="vartype_66971274-8d70-4766-8254-996bda8991b0">
<option value="1">
Integer</option>
<option value="2" selected="">
String</option>
<option value="3">
Date</option>
</select>
</div>
<div class="divTableCell">
<input type="text" name="varformat_66971274-8d70-4766-8254-996bda8991b0" class="vTextField" maxlength="20">
</div>
</div>
<div id="01ed7377-b526-4acf-a556-b87a1012091f" class="divTableRow">
<div class="divTableCell">
<input type="hidden" name="varname_01ed7377-b526-4acf-a556-b87a1012091f" value="items">
items
</div>
<div class="divTableCell">
<input type="text" name="varlabel_01ed7377-b526-4acf-a556-b87a1012091f" value="None" class="vTextField" maxlength="20">
</div>
<div class="divTableCell">
<select name="vartype_01ed7377-b526-4acf-a556-b87a1012091f">
<option value="1">
Integer</option>
<option value="2" selected="">
String</option>
<option value="3">
Date</option>
</select>
</div>
<div class="divTableCell">
<input type="text" name="varformat_01ed7377-b526-4acf-a556-b87a1012091f" class="vTextField" maxlength="20">
</div>
</div>
</div>
<!--div id="alldata" hx-get="/mst/htmx/get_schema/7" hx-trigger="load" hx-swap="beforeend" class="divTableBody">
</div-->
</div>
<div class="submit-row">
<input type="submit" value="Save" class="default" name="_save">
<p class="deletelink-box">Delete</p>
<input type="submit" value="Save and add another" name="_addanother">
<input type="submit" value="Save and continue editing" name="_continue">
</div>
<script id="django-admin-form-add-constants" src="/static/admin/js/change_form.js" async="">
</script>
<script id="django-admin-prepopulated-fields-constants" src="/static/admin/js/prepopulate_init.js" data-prepopulated-fields="[]">
</script>
</div>
</form></div>
<br class="clear">
</div>
<!-- END Content -->
<div id="footer"></div>
</div>
</div>
</div>
<!-- END Container -->
</body></html>
it's clear that all additional field is between form tags.
And here is my MailTemplateForm class
class MailTemplateForm(forms.ModelForm):
def clean(self):
cleaned_data = super().clean()
print(f'Cleaned Data:\n{cleaned_data}\n-------')
class Meta:
model = MailTemplate
fields = '__all__'
see that currently for all additional fields I only want to debug print it .
When I edit one of additional field and do save, I only got
Cleaned Data:
{'name': 'docx01', 'tfile': <FieldFile: uploads/mailtemplate/invoice-template_BCpUuSw.docx>}
-------
[16/Jan/2023 05:11:35] "POST /admin/myapp/mailtemplate/7/change/ HTTP/1.1" 302 0
[16/Jan/2023 05:11:35] "GET /admin/myapp/mailtemplate/ HTTP/1.1" 200 6823
[16/Jan/2023 05:11:35] "GET /admin/jsi18n/ HTTP/1.1" 200 3141
So, my question is:
How to read all the additional data in forms.py?
Kindly please give me any clue.
Sincerely
bino

Jinja code rendered using ajax is enclosed witin doublequorts in django project

I am developing a todo app using django as backend and html,css,bootstrap for frontend,
I used Ajax in this project to load data from server without refresh.
**Look at the image **
the {%csrf_token%} is passed through ajax but is is renderd in html page as a text within a double quort.
How to fix this
I want to render the {%csrf_token%} in the webpage without double quorts.
Ajax code
$.ajax({
type:'POST',
url:'/task/'+todo_id+'/new_todo/',
processData: false,
contentType: false,
data: data,
success: function(response){
console.log("**********Data send to backend");
var new_id = response['new_id'];
var new_color = response['new_color'];
var new_status = response['new_status']
var new_todo_note = response['new_todo_note']
if (new_todo_note == null){
my_note = " "
}
else{
my_note = new_todo_note
}
$("#"+todo_id).hide();
$.ajax({
type:'GET',
url:'/task/'+todo_id+'/new_todo/',
data:data,
dataType:'json',
success: function(response){
var todo_section = `<ol class="list-group mb-3 v1" id="${response.latest_todo.id}right">
<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto d-flex">
<div>
<div class="fw-bold">${response.latest_todo_name}</div>
<p style="font-size: x-small; margin:0;">${response.latest_todo_added_date}</p>
<div style="max-width: 100px; display:flex; ">
<div id="${new_id}task_note">
${my_note}
</div>
</div>
</div>
<div class="mt-1 ms-4">
<a href="{%url 'todo-details' todo.id%}">
<i class="fa-solid fa-arrow-up-right-from-square text-muted"></i>
</a>
</div>
</div>
<div class="d-flex flex-column">
<div style="align-self: flex-end;" id="${new_id}badge_live">
<span class="badge rounded-pill" id="${new_id}badge" style="background-color:${new_color};">&nbsp&nbsp&nbsp
</span>
</div>
<div class="mt-2 d-flex">
<div class="me-2">
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#exampleModal" style="font-size: xx-small;">
Note
</button>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Create Task Note</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="/todo/${new_id}/add_note/" method="post" id="task_note_form" name="${new_id}" enctype="multipart/form-data">
{%csrf_token%}
<div class="modal-body">
<div>
<h2>Add Task Note</h2>
</div>
<div class="mb-3">
<textarea name="note" id="note${new_id}" cols="15" rows="5" class="form-control" required></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary note_submit_btns" value="Create" data-bs-dismiss="modal" name="${new_id}">
</div>
</form>
</div>
</div>
</div>
</div>
<div id="${new_id}btn_live_change">
<div id="${new_id}btn_live">
<input type="submit" value="${new_status}" id="${new_id}"
class="btn btn-primary stat_btns"
style="font-size: xx-small;">
</div>
</div>
</div>
</div>
</li>
</ol>`
$("#display-todo-data").append(todo_section);
document.getElementById("task_note_form").reset();
},
});
}
});
}
});

DJANGO SENDING ORDERS TO THE DATABASE WITHOUT ANY PAYMENT GATEWAY

How do i send my order to my database in django
i'm beginner in django, and i'm trying to build an ecoomerce sute . although i'm not using the same payment gateway so its difficult for me to fllow up.
i want the order details to be saved in the database.
help
my orders view
from django.shortcuts import render
from django.http.response import JsonResponse
from django.shortcuts import render
from cart.cart import Cart
from .models import Order, OrderItem
Create your views here.
def add(request):
cart = Cart(request)
if request.POST.get('action') == 'post':
user_id = request.user.id
carttotal = cart.get_total_price()
# Check if order exists
if Order.objects.filter(order_key=order_key).exists():
pass
else:
order = Order.objects.create(user_id=user_id, full_name='name', address1='add1',
address2='add2', total_paid=carttotal, order_key=order_key)
order_id = order.pk
for item in cart:
OrderItem.objects.create(order_id=order_id, product=item['product'], price=item['price'], quantity=item['qty'])
response = JsonResponse({'success': 'Return something'})
return response
def payment_confirmation(data):
Order.objects.filter(order_key=data).update(billing_status=True)
def user_orders(request):
user_id = request.user.id
orders = Order.objects.filter(user_id=user_id).filter(billing_status=True)
return orders
{% extends "../store/base.html" %}
{% load static %}
{% block title %}Order{% endblock %}
{% block content %}
<style>
.account-form input,
{
border: 2px solid #ccc;
height: calc(2em + .75rem + 2px);
}
.form-control {
border: 2px solid #ccc;
}
.account-form input:focus {
border-color: #1497ff;
box-shadow: inset 0 0px 0px rgba(0, 0, 0, 0.075), 0 0 0px rgba(255, 0, 0, 0.6);
}
</style>
<div class="container-fluid">
<div class="row no-gutter">
<div class="col-md-12">
<div class="login d-flex align-items-center py-5">
<div class="container">
<div class="row">
<div id="payment-form" class="col-12 col-lg-6 mx-auto">
<h3 class="mb-3">Billing address</h3>
<!-- Error messages in this element -->
<div id="card-errors" class="a" role="alert"></div>
<form>
<div class="row g-3">
<div class="col-sm-7">
<label for="firstName" class="form-label">Customer Name</label>
<input type="text" name="name" class="form-control" id="custName" placeholder="" required>
<div class="invalid-feedback">
Valid first name is required.
</div>
</div>
<div class="col-12">
<label for="email" class="form-label">Email <span class="text-muted">(Optional)</span></label>
<input type="email" name="email" class="form-control" id="email" placeholder="you#example.com">
</div>
<div class="col-12">
<label for="address" class="form-label">Address</label>
<input type="text" name="address" class="form-control" id="custAdd" placeholder="1234 Main St" required>
<div class="invalid-feedback">
Please enter your address.
</div>
</div>
<div class="col-md-5">
<label for="country" name="country" class="form-label">Country</label>
<select class="form-select" id="country" required>
<option value="">Choose...</option>
<option>Zambia</option>
</select>
<div class="invalid-feedback">
Please select a valid country.
</div>
</div>
<div class="col-md-4">
<label for="state" name="state" class="form-label">State</label>
<select class="form-select" id="state" required>
<option value="">Choose...</option>
<option>Lusaka (Evelyne Hone College)</option>
</select>
<div class="invalid-feedback">
Please provide a valid state.
</div>
</div>
</div>
</div>
<hr class="my-4">
<h4 class="mb-3">Orders</h4>
<label for="card-element">Credit or debit card</label>
<div id="card-element" class="form-control form-control-payment">
<!-- Payment elements will appear here -->
</div>
<hr class="my-4">
<button id="submit" id="make-payment" class="btn btn-primary w-100 fw-bold">Order Now</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
var total={{'basket.get_subtotal_price'}}
document.getElementById("make-payment").addEventListener('click',function(e){
submitFormData()
})
function submitFormData(){
console.log("payment button clicked")
var userFormData={
'name':null,
'email':null,
'total':total
'address':null,
'state':null,
'country':null,
}
if (user=='AnonymousUser'){
userFormData.name=form.name.value
userFormData.name=form.email.value
userFormData.name=form.address.value
userFormData.name=form.state.value
userFormData.name=form.country.value
}
var url='/order_placed/'
fetch=(url,{
method:'post'
headers:{
'content-type':'application/json',
'x-CSRF_Token':csrf_token
},
body:JSON.stringify({'form':userFormData})
} )
</script>
{% endblock %}

Bootstrap modal as dropdown

<div id="lastcolumn" class="col-md-3">
<ul class="nav navbar-nav pull-right">
<li class="llogin"><a class="mlogin" data-target="#loginmodal" data-toggle="modal"><span class="glyphicon glyphicon-chevron-down pull-right"></span>Login</a></li>
<div class="modal" id="loginmodal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="Username">Username</label>
<input type="text" name="text" class="form-control">
</div>
<div class="form-group">
<label for="Password">Password</label>
<input type="Password" name="text" class="form-control">
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<li class="lsignup"><a class="msignup"><span class="glyphicon glyphicon-chevron-down pull-right"></span>Signup</a></li>
<li class="lcart"><a class="mcart"><span class="glyphicon glyphicon-shopping-cart pull-right"></span>Item</a></li>
</ul>
</div>
</div>
</div>
I want to show bootstrap modal as dropdown under login currently my modal is showing in middle of the screen what i have to do to achieve the desired behaviour, kindly help.enter image description here
Move the .modal div in the li that you want to attach the modal with. Then define position:relative; for that li and position:absolute; for that .modal.
Here's a working snippet. I removed the .modal-backdrop and edited padding and margin for modal. You can ignore them since they are not relevant to the basic problem.
.nav.navbar-nav li{
float:left;
}
.nav.navbar-nav li a.mlogin{
position:relative;
}
div.modal#loginmodal{
position:absolute;
width:200px;
height:300px;
top:30px;
left:0;
padding:0;
margin:0;
}
div.modal#loginmodal .modal-footer{
padding:5px;
margin:0;
}
div.modal#loginmodal .modal-body{
padding:10px 20px;
margin:0;
}
div.modal#loginmodal .modal-header{
padding:5px 20px;
margin:0;
}
.modal-backdrop{
display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="lastcolumn" class="col-md-3">
<ul class="nav navbar-nav pull-right">
<li class="llogin"><a class="mlogin" data-target="#loginmodal" data-toggle="modal"><span class="glyphicon glyphicon-chevron-down pull-right"></span>Login</a>
<div class="modal" id="loginmodal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="Username">Username</label>
<input type="text" name="text" class="form-control">
</div>
<div class="form-group">
<label for="Password">Password</label>
<input type="Password" name="text" class="form-control">
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</li>
<li class="lsignup"><a class="msignup"><span class="glyphicon glyphicon-chevron-down pull-right"></span>Signup</a></li>
<li class="lcart"><a class="mcart"><span class="glyphicon glyphicon-shopping-cart pull-right"></span>Item</a></li>
</ul>
</div>

Space created at the bottom of a panel with foundation framework

I'm playing with foundation framework and i'm trying to make a simple login form with it.
Here's my markup
<form>
<div class="row">
<div class="large-4 columns">
<div class="panel">
<div class="row">
<div>
<label>Login: <input type="text" placeholder="Login">
</div>
</div>
<div class="row">
<div>
<label>Senha <input type="password">
</div>
</div>
<div class="row">
<input type="submit" value="OK" class="tiny button right">
Esqueci minha senha
</div>
</div>
</div>
</div>
</form>
But at the bottom of it, there's some space created.
How can i remove this space?
The space you are talking about is created by the buttons bottom margin. To remove it simply add a CSS class like such:
.panel .button { margin-bottom: 0; }
Working example: JSFIDDLE