Closed simonw closed 7 months ago
Figured out the right pattern for this - it needs this change:
- config = post_vars._data.copy()
- config.pop("csrftoken", None)
+ config = {field.name: field.data for field in form}
Plus this change to that multi column selecting form:
-class MultiCheckboxField(SelectField):
+class MultiCheckboxField(SelectMultipleField):
widget = ListWidget(prefix_label=False)
option_widget = CheckboxInput()
Thanks to this code: https://github.com/datasette/datasette-enrichments/blob/33d0e4b0f9a415d4842d041378f3cd5414635c93/datasette_enrichments/views.py#L172-L173
The
config
dictionary ends up full of things like{"template": ["this is the template"]}
which means I have to write code like this:https://github.com/datasette/datasette-enrichments/blob/33d0e4b0f9a415d4842d041378f3cd5414635c93/example-enrichments/jinja_sandbox.py#L61-L62
I did this because I wanted to support the case of a multi-select style interface for selecting a list of items here:
https://github.com/datasette/datasette-enrichments/blob/33d0e4b0f9a415d4842d041378f3cd5414635c93/example-enrichments/uppercase.py#L23-L37
But there should be a better way of doing this - I want config to mostly be single valued keys, with lists only for the keys that need it.