Reputation: 15
I have data model with one parent and two child tables. I want to change custom add/edit forms based on input type text entry fields to have: - pull down menus (made with SELECT/OPTION elements) with predefined elements, - checkboxes.
The main page is SQLFORM.smartgrid with references to children (which I want to have several custom add/edit forms).
The URL's for change are for example:
http://host.com:8000/First/default/index/recipe/edit/recipe/4 (parent table)
http://host.com:8000/First/default/index/recipe/rule.recipe_id/4/new/rule (child table)
What should I do to change default views of SQLFORM.smartgrid "Add record" and "Edit" action buttons?
Upvotes: 0
Views: 1784
Reputation: 25536
If you just want to change the form widgets used for particular fields, you do not have to customize the create/update forms directly. Instead, you can just specify the appropriate validators and custom widgets:
db.define_table('mytable',
Field('field1', requires=IS_IN_SET(['a', 'b', 'c'])),
Field('field2', requires=IS_IN_SET(['x', 'y', 'z'], multiple=True),
widget=SQLFORM.widgets.checkboxes.widget))
The IS_IN_SET
validator will automatically produce a drop-down element for field1. The default for field2 would be a multi-select box, but the "widget" argument changes it to checkboxes.
If you still need to do some form customization, though, you can do something like this in the view:
{{if ('new' in request.args) or ('edit' in request.args):}}
[custom form code goes here]
{{pass}}
Upvotes: 2