Do you have default=False in the database?

SQLFORM and and FORM take a parameter hidden=dict(key='value')

Massimo

On Nov 21, 6:32 am, billf <[EMAIL PROTECTED]> wrote:
> I am investigating a possible solution to the above problem that would
> return fieldname=OFF if a displayed checkbox is unchecked.
>
> This would enable web2py to retain existing values for a boolean field
> if a request.var was not present.
>
> However, I recognise that some people may consider returning
> fieldname=OFF a contravention of protocol - does anyone feel like
> that?
>
> FYI the solution is to add a hidden "off" checkbox (value='off') for
> each displayed checkbox (both with the same name) and when the normal
> checkbox is clicked setting the "off checkbox appropriately so that
> whatever the status of the normal checkbox either name=on or name=off
> will be returned.
>
> Any thoughts gratefully received.
>
> On Nov 21, 8:13 am, billf <[EMAIL PROTECTED]> wrote:
>
> > If the following explanation is correct it is a big coincidence
> > because I have just been looking at this behaviour.
>
> > When a form is submitted, if there is no parameter for a field then
> > one of 2 things happen (simplified):
>
> > If it is NOT a checkable form control (checkable=check box or radio
> > button) then the original form value is used.  In the case of an
> > existing record, this will be the value in the existing record. In the
> > case of a new record then any defailt will be used.
>
> > If it IS a checkable form control then it is impossible to distinguish
> > between a missing parameter and an unchecked control because CGI
> > doesn't send "mycheckbox=off" - it just doesn't send anything.  So to
> > be able to set a boolean field to false, web2py must say
> > missing==unchecked.
>
> > In your case, you set checkboxes on page2 and everything is fine.
> > When you amend page 1 and submit, no checkboxes are present so web2py
> > sets the associated fields to False. You go back to page 2 and, lo and
> > behold, all the checkboxes are unchecked.
>
> > The only solution, given the current setup, is that any fields
> > represented as checkable controls but not displayed in the current
> > form must be set up in the form as "hidden" so that checked fields are
> > returned even if they are not displayed.
>
> > I think it should be possible to create the "hidden" fields
> > automatically in SQLFORM/FORM, although supporting "custom
> > forms" (where a developer may not include a field that the standard
> > SQLFORM would include) could be a complication.
>
> > On Nov 21, 6:20 am, "Wes James" <[EMAIL PROTECTED]> wrote:
>
> > > I have an app that on one page I have a set of fields (first 20 fields
> > > of say 50) I have manually placed.  All saves well and when I go to
> > > another page and come back all is well.
>
> > > On a separate page, I edit the rest of these fields.  Part of these
> > > are check box fields and some others including textarea fields.
>
> > > When I save the data on this page - all is well.
>
> > > I then go back to the first page and make a change and save the data -
> > > fine, but if I go back to the page with the check boxes, they are all
> > > cleared out - I look in the DB in admin area and yes, they are all set
> > > to False.  But the textarea fields do not do this on this page - they
> > > keep their data just fine.
>
> > > So I created a test page and made a controller like I already have:
>
> > > form=t2.create(db.student)
> > > return dict(form=form)
>
> > > and then in a test.html do {{=form}
>
> > > I then save the page with a check box selected - fine - that works.
>
> > > I then go back to my first page and make a change and save.  Go back
> > > to the test page and the check box is cleared.
>
> > > Why is it doing this?
>
> > > thx,
>
> > > -wj
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to