나는 선택 위젯이있는 CRUD 양식이 있습니다. 위젯의 옵션은 동적입니다. 다른 테이블에서 값을 가져 오므로 태그를 사용할 수 없습니다. 나는이 방법을 사용하여 컨트롤러의 값을 변경하려고 : 나는 메소드를 호출하고 양식을 검사web2py : 가벼운 형태로 위젯 수정
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
후, 나는 양식이 성공적으로 수정 된 것을 볼 수 있습니다. 뷰 측면에서, 나는 사용자 지정보기를 사용하는 등 같은 폼을 표시하기 위해 노력하고있어 :
{{=form.custom.begin}} {{=form.custom.widget.customized_field}}
{{=form.custom.submit}} {{=form.custom.end}}
을하지만, 그것은 여전히 내게는 수정되지 않은 원래 위젯을 보여줍니다. 내가 도대체 뭘 잘못하고있는 겁니까? 이 작업을 수행하는 더 좋은 방법이 있습니까?