Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Working with WTForms FieldList

$(document).ready(function () {
    $('#add_another_button').click(function () {
        clone_field_list('fieldset:last');
    });
});

function clone_field_list(selector) {
    var new_element = $(selector).clone(true);
    var elem_id = new_element.find(':input')[0].id;
    var elem_num = parseInt(elem_id.replace(/.*-(d{1,4})-.*/m, '$1')) + 1;
    new_element.find(':input').each(function() {
        var id = $(this).attr('id').replace('-' + (elem_num - 1) + '-', '-' + elem_num + '-');
        $(this).attr({'name': id, 'id': id}).val('').removeAttr('checked');
    });
    new_element.find('label').each(function() {
        var new_for = $(this).attr('for').replace('-' + (elem_num - 1) + '-', '-' + elem_num + '-');
        $(this).attr('for', new_for);
    });
    $(selector).after(new_element);
}
Comment

PREVIOUS NEXT
Code Example
Python :: odoo manifest 
Python :: not equal to in python 
Python :: how to split strings in python 
Python :: encapsulation in python 
Python :: websocket api python on close 
Python :: flask arguments in url 
Python :: qtimer singleshot 
Python :: python unittest multiple test cases 
Python :: numpy shape 
Python :: remove list from list python 
Python :: python terminal ui 
Python :: Python Program to Shuffle Deck of Cards 
Python :: capitalise texts 
Python :: how to input a picture into opencv raspberry pi 
Python :: python telegram bot async 
Python :: python use getcontext 
Python :: python using end keyword 
Python :: or en python 
Python :: python re split 
Python :: pygame template 
Python :: pandas set one column equal to another 
Python :: DIF_GCD 
Python :: string + string in python 
Python :: extract images from pdf 
Python :: Model In View Django 
Python :: how to print a value of a key in nested dictionary python 
Python :: Split a list based on a condition 
Python :: dict comprehensions 
Python :: what does enumerate do in python 
Python :: Python Renaming a Directory or a File 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =