Hi,
I am trying to create a `CharFieldMultiple`, equivalent to the MultipleHiddenInput or SelectMultiple.
The goal is to have multiple CharField returned as a list, but have not been able to recreate it. My code thus far is:
class CharFieldMultiple(forms.widgets.Input):
def render(self, name, value, attrs=None):
if value is None:
value = []
final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
inputs = []
for i, v in enumerate(value):
input_attrs = dict(value=force_text(v), **final_attrs)
inputs.append(format_html('<input{} />', flatatt(input_attrs)))
return mark_safe('\n'.join(inputs))
I am trying to figure out how 'value' is set. I noticed that when I manually put value = ['a','b','c'], I will get 3 CharFields, great! But I cannot figure out how to pass that value parameter.
The type-field is still set to None, but I can figure that out later.
Thanks in advance!
- Farhan