While loop not seeing dynamic created form fields
So everything looks good on the html and css where the dynamically created objects have the correct attributes.
let $this = $("#id_variant_0")
let $clone = $this.clone()
let name = $clone.attr('name')
let n = count
name = 'variant_' + n
count++
$clone.val('')
$clone.attr('name', name)
let new_id = "id_" + name
$clone.attr('id', new_id)
$clone.appendTo($this.parent())
$this.addClass('form-control')
})
but I can't seem to get the while loop to work, it only sees the first one.
variants = set()
i = 0
field_name = 'variant_%s' % (i,)
while self.cleaned_data.get(field_name):
variant = self.cleaned_data[field_name]
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
print(variant)
if variant in variants:
self.add_error(field_name, 'Duplicate')
else:
variants.add(variant)
i += 1
field_name = 'variant_%s' % (i,)
self.cleaned_data["variants"] = variants
def get_variant_fields(self):
for field_name in self.fields:
if field_name.startswith('variant_'):
yield self[field_name]
What am I doing wrong here?