Reputation: 2102
I have the following code:
<form class="square" action="{% url 'interface:modify_device_perform' %}" method="post">
{% csrf_token %}
<div class="form-group">
<label>ID device</label>
<input class="form-control" name="device_id" value="{{ device.id }}" readonly />
</div>
<div class="form-group">
<label>Device name</label>
<input class="form-control" name="device_human" value="{{ device.human_id }}" placeholder="Example: Box 2" />
</div>
<div class="form-group">
<label>Associated patient</label>
{% if device.user_set.get.id != '' %}
<input class="form-control" value= "{{ device.user_set.get.id }}" readonly> </input>
{% else %}
<input class="form-control" value= "No patient" readonly> </input>
{% endif %}
</div>
<div class="form-group">
<label>Device position</label>
<select name="position_id" class="form-control">
{% for position in position_list %}
{% if position == device.position %}
<option selected="selected">{{ position.id }}</option>
{% else %}
<option>{{ position.id }}</option>
{% endif %}
{% endfor %}
{% if device.position == None %}
<option selected="selected"> No position </option>
{% else %}
<option> No position </option>
{% endif %}
</select>
</div>
<div class="form-group square_button">
<button class="btn btn-warning btn-md form-control" type="submit"> Modify Device </button>
</div>
</form>
This represents the following:
The problem is that I want to add a button on the right of No patient
that makes a post request, making possible to remove a patient associated in case it has one.
How I can add that post request inside a post request?
Upvotes: 0
Views: 332
Reputation: 291
You can Do that With ajax, for that you need to add some code in your javascript/jquery.
You can put button to the right side of the "No patient" and add a click event for that in javascript. make ajax request in with post url and get your response in the success function of ajax. you can refer ajax and its methods on https://www.w3schools.com/jquery/jquery_ref_ajax.asp
Hope it will help you.
Upvotes: 1