html - Python Jinja2 For Range -
i'm learning python/jinja2 , found problem don't know how solve it. i'm passing list of data jinja, , list, creates table. table ok , works fine. when want pass 1 attribute of list/table form, looses reference of list , sent information first item of list. let me explain better:
{% value in listresult %} <tr> <td><center>{{ value.date }}</center></td> {% set ident = value._id%} <td>{{ident}}</td> <td> <form name="info_form" class="form-inline" action="/changetime1" method="post"> <div id="enquirypopup" class="modal fade in" role="dialog"> <div class="modal-dialog"> <!-- modal content--> <div class="modal-content row"> <div class="modal-header custom-modal-header"> <h4 class="modal-title">{{ident}}</h4> </div> </div> </div> </div> </form> <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#enquirypopup">change</button> </td> {% endfor %}
the table creation @ point correct. in line 5, prints 1 id of each line in table(different id). when ask print same variable, @ line 14, prints "ident" of first element of list. seems when call form, looses reference of element on list.
so, doesn't matter element of list click(button "change" line 20), id comes in pop first element.
any idea?
the issue html element ids. since you're creating each form same id (#enquirypopup
), browser returning first element in page—i.e. first time sees #enquirypopup
id*.
a quick workaround setting ids jinja ident
variable so:
<div id="enquirypopup_{{ ident }}" class="modal fade in" role="dialog">...</div>
and
<button type="button" class="btn..." data-toggle="modal" data-target="#enquirypopup_{{ ident }}">change</button>
but there countless other solutions using different selectors.
*this not standardized behavior , differs across browsers, reason why it's bad practice
Comments
Post a Comment