Django: How to add an extra form to a formset after it has been constructed?

后端 未结 4 1167
误落风尘
误落风尘 2021-02-01 21:44

This is roughly what I\'m trying to do:

def post(request):
    VehicleFormSet = formset_factory(StaffVehicleForm)
    if request.method == \'POST\':
        vehi         


        
4条回答
  •  失恋的感觉
    2021-02-01 22:27

    I use RegEx in my Vue.js method:

    addForm: function () {
        this.count++
        let form_count = this.count
        form_count++
    
        let formID = 'id_form-' + this.count
        incremented_form = this.vue_form.replace(/form-\d/g, 'form-' + this.count)
        this.formList.push(incremented_form)
        this.$nextTick(() => {
            let total_forms = document.getElementsByName('form-TOTAL_FORMS').forEach
            (function (ele, idx) {
                ele.value = form_count
            })
        })
    },
    
    delForm: function () {
        if (this.count != 0) {
            this.count--
            let form_count = this.count
            form_count++
    
            let formID = 'id_form-' + this.count
            this.formList.pop()
            this.$nextTick(() => {
                let total_forms = document.getElementsByName('form-TOTAL_FORMS').forEach
                (function (ele, idx) {
                    ele.value = form_count
                })
            })
        }
        else return
    },
    

提交回复
热议问题