Re: [web2py] Temporary changing default values of a Form
I found the answer searching through the group posts: form.element(_name='email')['_readonly']=True although this doesn't seem to be documented in the manual, and even looking through the gluon directory (and grepping for _readonly ) didn't reveal anything. Would this have been obvious to someone more proficient with web2py (I've only been using it for about a month)? thx! Luis.
Re: [web2py] Temporary changing default values of a Form
One more question: How do I make the pre-populated elements of the form appear read-only (so that they cannot be altered)? I've tried in the view: {{=form.custom.begin}} First name: {{=predef.fname}} Last name: {{=predef.lname}} Email: {{=predef.email}} Password: {{=form.custom.widget.password}} Verify password: {{=form.custom.widget.password_two}} {{=form.custom.submit}} {{=form.custom.end}} but then the elements for which I don't use the widget (to avoid being edited), seem not to be passed with the submit ( the auth.register method did not accept the form as complete ) is there some way to set an element of a form to be read-only? Thanks again! Luis.
Re: [web2py] Temporary changing default values of a Form
That worked great!!! Thanks so much, Anthony!!! L. On Tue, Jul 5, 2011 at 10:23 AM, Anthony wrote: > I'm not sure you can pre-populate a registration form that way. > form.vars.email has to be set after the form is created but before > form.accepts is called -- however, auth.register() creates the form and > calls form.accepts. Instead, you can pre-populate by manipulating the form > DOM directly: > > form.element(_name='email').update(_value='lu...@vision.caltech.edu') > > > Anthony > > On Tuesday, July 5, 2011 1:08:31 PM UTC-4, Luis Goncalves wrote: > >> This doesn't seem to work with auth() forms: >> >> form = auth.register() >> >> form.vars.email = 'lu...@vision.caltech.edu' >> >> return dict(form=form) >> >> doesn't show the predefined value for 'email' in a view that renders >> {{=form}} >> >> Does anybody know why? >> >> Thanks!! >> Luis. >> >
Re: [web2py] Temporary changing default values of a Form
I'm not sure you can pre-populate a registration form that way. form.vars.email has to be set after the form is created but before form.accepts is called -- however, auth.register() creates the form and calls form.accepts. Instead, you can pre-populate by manipulating the form DOM directly: form.element(_name='email').update(_value='lu...@vision.caltech.edu') Anthony On Tuesday, July 5, 2011 1:08:31 PM UTC-4, Luis Goncalves wrote: > This doesn't seem to work with auth() forms: > > form = auth.register() > > form.vars.email = 'lu...@vision.caltech.edu' > > return dict(form=form) > > doesn't show the predefined value for 'email' in a view that renders > {{=form}} > > Does anybody know why? > > Thanks!! > Luis. >
Re: [web2py] Temporary changing default values of a Form
This doesn't seem to work with auth() forms: form = auth.register() form.vars.email = 'l...@vision.caltech.edu' return dict(form=form) doesn't show the predefined value for 'email' in a view that renders {{=form}} Does anybody know why? Thanks!! Luis.
Re: [web2py] Temporary changing default values of a Form
> Does anybody know how to do it for a select box? > Select box is rendered because it's a foreign key that reference another table. After you have created the form but before if form.accepts define your default. form = SQLFORM(db...) form.vars.type = 'cleaner' if form.accepts.. This should work. Kenneth
Re: [web2py] Temporary changing default values of a Form
Does anybody know how to do it for a select box? Select box is rendered because it's a foreign key that reference another table.
Re: [web2py] Temporary changing default values of a Form
There is atleast two other ways of doing this in the controller on-the-fly. Before you create the FORM object you can do: db.table.field.default = 0 (you temporarly change what you have defined i models) or after you have created the FORM but before if form.accepts form.vars.field = something Kenneth 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.
[web2py] Temporary changing default values of a Form
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.