I have a CRUD form that has a select widget. The options in the widget are dynamic. I cannot use tags, as the values are coming from other tables. I am trying to change the values in the controller using this method:
def change_widget(form, id, widget):
"Tries to find a widget in the given form with the given id and swaps it with the given widget"
for i in range( len(form[0].components) ):
if hasattr(form[0].components[i].components[1].components[0], 'attributes'):
if '_id' in form[0].components[i].components[1].components[0].attributes:
if form[0].components[i].components[1].components[0].attributes['_id'] == id:
form[0].components[i].components[1].components[0] = widget
return True
return False
After I call the method and inspect the form, I can see that the form has been successfully modified. On the view side, I'm using a custom view and trying to display the form like so:
{{=form.custom.begin}} {{=form.custom.widget.customized_field}}
{{=form.custom.submit}} {{=form.custom.end}}
But, it still shows me the original unmodified widget. What am I doing wrong? Is there a better way to do this?