I am looking to add some structure to my client side code and have been reading about knockout.js
. I have been reading the documentations and have a simple question
Another way is to use django-crispy-forms and define data-bind
attributes in the layout:
def __init__(self, *args, **kwargs):
super(SomeForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
Div('field_1',
Field('field_2', data_bind='value: field_2')),
HTML("{% if success %} Operation was successful
{% endif %}"),
)
Then in the template you only do:
{% crispy form form.helper %}
and voila.
Cripsy-forms is even more powerful than that and allows you to define your own layout templates etc.