laundmo
unread,Oct 15, 2025, 8:47:29 AM (4 days ago) Oct 15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to py4web
Hi Massimo and others,
Currently, the Form class seems more complex than necessary, since it contains, essentially, 2 code paths:
- When a Table object is passed
- When a list/tuple of Fields is passed
Having looked at it a bit, I think a good way to simplify this would be to convert one of them to the other. That means either of these:
- Standardise on List[Field]: When a Table object is passed, loop over all of the Fields that should be included (readable=True/writable=True) and extract them to the list of Fields.
- Standardise on Table: When a List[Field] is passed, create a clone of the Table (like with_alias does, should probably at that point move that logic from Table.with_alias to a new Table.clone) and set the readable/writable/required of all fields not in the List[Field] to False. Use this as the table. I don't have any idea how to handle custom fields with this.
Personally, I prefer the first option, standardizing on List[Field] - its less complex and the handling of custom fields is likely going to be far easier. A variant of this idea is to convert both List[Field] and Table to List[FormInput] or similar - a class which stores only whats needed to render and handle the Form, akin to the Column class for Grid. This could be very generic, with FormInput only defining methods for update/delete. Potentially, FormInput could also handle its own validation. This could then allow users far more flexibility for custom form inputs and their handling, such as completely custom update handlers. For delete, by default only the FormInput created from id Fields would handle delete, by deleting the corresponding row.
Does this seem like a work-able idea?