Dynamically generate client-side HTML form control using JavaScript and server-side Python code in Google App Engine

Posted by gisc on Stack Overflow See other posts from Stack Overflow or by gisc
Published on 2012-07-05T08:05:56Z Indexed on 2012/07/05 9:16 UTC
Read the original article Hit count: 227

I have the following client-side front-end HTML using Jinja2 template engine:

{% for record in result %}
    <textarea name="remark">{{ record.remark }}</textarea>
    <input type="submit" name="approve" value="Approve" />
{% endfor %}

Thus the HTML may show more than 1 set of textarea and submit button.

The back-end Python code retrieves a variable number of records from a gql query using the model, and pass this to the Jinja2 template in result. When a submit button is clicked, it triggers the post method to update the record:

def post(self):
    if self.request.get('approve'):
        updated_remark = self.request.get('remark')
        record.remark = db.Text(updated_remark)
        record.put()

However, in some instances, the record updated is NOT the one that correspond to the submit button clicked (eg if a user clicks on record 1 submit, record 2 remark gets updated, but not record 1).

I gather that this is due to the duplicate attribute name remark. I can possibly use JavaScript/jQuery to generate different attribute names. The question is, how do I code the back-end Python to get the (variable number of) names generated by the JavaScript?

Thanks.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about python