Excellent question:

db.mytable.myfield.default = request.args(0)
form = SQLFORM(db.mytable)


On Jan 4, 4:28 pm, Fabiano - deStilaDo <[email protected]>
wrote:
> Hi,
>
> I have a default value for a field defined on the table definition,
> along with its validators.
>
> I want to create a form with a different initial value for some
> fields, based on the link the user clicked. Something like "add new
> item for this category" and the new item form come with that category
> pre-filled.
>
> The way I found to do this was:
>
>     form = SQLFORM(db.mytable)
>     form.custom.widget['myfield']['value'] = request.args(0)
>     form.custom.widget['myfield']._postprocessing()
>
> the _postprocessing() call was necessary in case of multiple options
> widget (like Selects), else the selected option wouldn't be updated.
>
> It works fine, but I believe I am messing with the inners of the
> object, a bad programming practice, as the internal implementation may
> change and break my app.
>
> Is there a proper way of doing this?
>
> Kind regards,
>
> Fabiano.

Reply via email to