Forms have Fields, Fields have a value. However, they only get a value after the form has been submitted.
- How should I store this value? Should I give every field a value attribute,
field.value,- leave it as
Noneprior to posting, and fill it in afterwords? - Omit it completely, and dynamically add it?
- Store it on the form instead, like
form.data['field']. - Create a a wrapper class
FieldWithDatato avoid any inconsistent states (if you have an object of this type, you know it has data) and allows me to set the data in the initializer rather than accessing attributes directly (although I guess this isn’t so different from using a setter)
- leave it as
- How should I provide access to the field data through the
Formobject? Options:form.fields['name'].value(how it’s presently being stored internally)form.data['field'](create a proxy “data” class that retrieves the real data off the field, or re-arrange the internals to actually store the data like this)form.field.value– looks fairly nice, but then I’d have two references to the same field, one asform.fieldand one asform.fields['field']which I need internally so that I can iterate over them
Too many design decisions. Driving me nuts. This is what sucks about solo’ing a project.
It really depends on how you interact with the structures in question. Do you manipulate
FormandFieldobjects prior to assigning them values? Do you need to frequently iterate over all the givenFields? Do you needFormonce it’s been submitted? Etc.I’d suggest writing some/all of the code that uses
Formand figure out how you want to interact withFormdata, and what your ideal interface would look like.