开发者

Get ID of total_form_count?

开发者 https://www.devze.com 2023-01-11 03:56 出处:网络
When using a formset, you need to a开发者_运维问答dd {{formset.management_form}} to your form. This renders 3 fields, one of which is TOTAL_FORM_COUNT. I want to get the ID of this field so that I can

When using a formset, you need to a开发者_运维问答dd {{formset.management_form}} to your form. This renders 3 fields, one of which is TOTAL_FORM_COUNT. I want to get the ID of this field so that I can modify its value via JS. How can I do that?

I'm trying stuff like formset.management_form.TOTAL_FORM_COUNT and .fields.TOTAL_FORM_COUNT to get the field, and then I think auto_id should hold the attribute I need, but I can't figure out how to access it.


It should be possible to get the value of the total_form_count from the field.

When I needed the same however, I got it from within jQuery:

$('id_your-model-name_set-TOTAL_FORMS').val()

Since I guess you are going to be replacing the value because you manually add more forms via javascript, you are going to have to select the element, to increment/set it. You might as well get it's defined value there.

0

精彩评论

暂无评论...
验证码 换一张
取 消