Hey all,
Was just wondering about this....currently web2py re-runs the form
validations for every single field, even if you only update one field. For
example, in the models file:
db.define_table('user',
format = '%(id)s')
db.define_table('thing',
Field('name', length=100),
Field('type', length=100),
Field('size', length=100),
Field('firstUserId', db.user),
Field('secondUserId', db.user),
Field('thirdUserId', db.user),
format = '%(type)s'
)
So now, if I want make a form to only update thing.type, it will return a
form error unless I also supply the firstUserId, secondUserId, and
thirdUserId fields. This is because foreign field references have a
validation for IS_IN_DB by default. I can work around this by making their
input fields hidden, but isn't that a bit of a hassle? If I have a page
that has separate forms for thing.name, thing.type, thing.size,
thing.firstUserId, etc., (because they are on different parts of the page,
and there are forms for other tables in between), then I have to
redundantly enter all the hidden userId fields for each form.
For example, if I want to have a form that just updates 'type', currently I
have to do:
<form name="thing">
<input name="type" type="text" value="{{=thing.type}}" />
<input name="firstUserId" type="hidden" value="{{=thing.firstUserId}}"
/>
<input name="secondUserId" type="hidden" value="{{=thing.secondUserId}}"
/>
<input name="thirdUserId" type="hidden" value="{{=thing.thirdUserId}}"
/>
<input name="_formname" type="hidden" value="thing" />
<input name="id" type="hidden" value="{{=thing.id}}" />
</form>
I know there is a way around this by setting the 'fields' attribute in
SQLFORM, but what if I want to update firstUserId, secondUserId, or
thirdUserId using the same SQLFORM? Then I'd have to make a SQLFORM for
each of firstUserId, secondUserId, and thirdUserId. So, in total, I'd have
at least 4 almost-identical SQLFORMs in the same controller action.
This is just an example, but you can see how in a real-world application
this could get lead to a lot of duplicate code and get pretty messy.
If web2py only performed validations on the fields that are being updated
(instead of on every field), then this problem would be solved, and much
duplicate code would be avoided. Also, the code would run faster,
especially in cases where there are many fields and validations need to be
done on every one of them.
What do you guys think?
Thanks
--