[web2py] Re: Confused about hidden fields

2011-11-03 Thread Omi Chiba
Thanks David !!

On Nov 3, 10:31 am, TheSweetlink  wrote:
> I am not certain that the case is the same but one thing I noticed
> with SQLFORM.factory and hidden fields was that in order to pass a
> hidden field from the SQLFORM.factory(...hidden=dict(Sir Robin: 'the
> brave')) required that a Field(...) be defined for it in the form
> definition.
>
> To make it hidden, just set readable=False, writable=False.  So what I
> did was something like this:
>
> SQLFORM.factory(Field(...), Field(...), Field('sirRobin',
> readable=False, writable=False...),
> hidden=dict(sirRobin: 'the brave')
>
> This will create a hidden field that isn't shown or which you can
> change and its value is passed in from the controller.
>
> You're already using a custom form and that's important too as the
> hidden field must be somewhere in your custom form so that it can
> submit your hidden field along with the rest of the form.
>
> I hope this is helpful to you Omi.
>
> David
>
> On Nov 1, 6:20 pm, Omi Chiba  wrote:
>
>
>
>
>
>
>
> > Sorry, I'm so confused and hard to explain but...
>
> > I have a field which value was set from another table and don't want
> > to show on the user. I just want to set default value in controller
> > and submit the form with the fields user filled in.
>
> > Do I need to include the field in the view but make it hidden ?
>
> > or
>
> > Use SQLFORM(, hidden=dict(FFTSCD='aaa'),
>
> > below is a part of my view FFTSCD is the field I don't want to show.
> > --
> > {{extend 'layout.html'}}
> > Fedex Request Form - {{=keyHJ}}
> > Report Date: {{=form.custom.widget.FFTRD}}
> > {{=form.custom.begin}}
> > 
> > User Information
> > Created by: {{=form.custom.widget.FFCUSR}}
> > Created on: {{=form.custom.widget.FFCDAT}}
>
> > {{=form.custom.submit}}
> > 
> > {{=form.custom.widget.FFTSCD}}
> > {{=form.custom.end}}


[web2py] Re: Confused about hidden fields

2011-11-03 Thread TheSweetlink
I am not certain that the case is the same but one thing I noticed
with SQLFORM.factory and hidden fields was that in order to pass a
hidden field from the SQLFORM.factory(...hidden=dict(Sir Robin: 'the
brave')) required that a Field(...) be defined for it in the form
definition.

To make it hidden, just set readable=False, writable=False.  So what I
did was something like this:

SQLFORM.factory(Field(...), Field(...), Field('sirRobin',
readable=False, writable=False...),
hidden=dict(sirRobin: 'the brave')

This will create a hidden field that isn't shown or which you can
change and its value is passed in from the controller.

You're already using a custom form and that's important too as the
hidden field must be somewhere in your custom form so that it can
submit your hidden field along with the rest of the form.

I hope this is helpful to you Omi.

David

On Nov 1, 6:20 pm, Omi Chiba  wrote:
> Sorry, I'm so confused and hard to explain but...
>
> I have a field which value was set from another table and don't want
> to show on the user. I just want to set default value in controller
> and submit the form with the fields user filled in.
>
> Do I need to include the field in the view but make it hidden ?
>
> or
>
> Use SQLFORM(, hidden=dict(FFTSCD='aaa'),
>
> below is a part of my view FFTSCD is the field I don't want to show.
> --
> {{extend 'layout.html'}}
> Fedex Request Form - {{=keyHJ}}
> Report Date: {{=form.custom.widget.FFTRD}}
> {{=form.custom.begin}}
> 
> User Information
> Created by: {{=form.custom.widget.FFCUSR}}
> Created on: {{=form.custom.widget.FFCDAT}}
>
> {{=form.custom.submit}}
> 
> {{=form.custom.widget.FFTSCD}}
> {{=form.custom.end}}


[web2py] Re: Confused about hidden fields

2011-11-03 Thread DenesL
On second thought it is not broken.
request.vars are processed during form.accepts
and form.vars will contain validated values afterwards.

Since in this case field2 is not in request.vars,
form.vars.field2 will be set to None.

To set the value of field2, without it coming in thru request.vars
(i.e. field2 is not in the form), one should use onvalidation to
change it after it has been validated and before it is written out to
the DB.



On Nov 2, 10:45 am, Philip Kilner  wrote:
> Hi,
>
> On 02/11/2011 13:59, DenesL wrote:
>
>
>
> >>      form.vars.field2 = 'BBB'
>
> > This should work to pre-populate the value of field2 with 'BBB' but it
> > seems to be broken in 1.99.2
>
> I'm so glad you said that - this was one of the things I tried in
> troubleshooting my "Passing values to CRUD create from controller"
> issue, and I was completely baffled as to why it was not working!
>
> --
>
> Regards,
>
> PhilK
>
> 'a bell is a cup...until it is struck'


[web2py] Re: Confused about hidden fields

2011-11-02 Thread Omi Chiba
Thanks everyone.

I'm easy person so I use the CSS to hide it just like JmixIII
mentioned.
something like this.

View


  jQuery(function(){
jQuery('.hidden').hide();
  };


{{extend 'layout.html'}}

{{=form.custom.begin}}
Field1: {{=form.custom.widget.field1}}
Field2: {{=form.custom.widget.field1}}
{{=form.custom.submit}}
{{=form.custom.end}}


On Nov 2, 12:32 pm, JmiXIII  wrote:
> Hello,
>
> For hidden field I usually used 

Re: [web2py] Re: Confused about hidden fields

2011-11-02 Thread JmiXIII
Hello,

For hidden field I usually used 

Re: [web2py] Re: Confused about hidden fields

2011-11-02 Thread Philip Kilner

Hi,

On 02/11/2011 13:59, DenesL wrote:


 form.vars.field2 = 'BBB'


This should work to pre-populate the value of field2 with 'BBB' but it
seems to be broken in 1.99.2



I'm so glad you said that - this was one of the things I tried in 
troubleshooting my "Passing values to CRUD create from controller" 
issue, and I was completely baffled as to why it was not working!



--

Regards,

PhilK


'a bell is a cup...until it is struck'



[web2py] Re: Confused about hidden fields

2011-11-02 Thread DenesL


On Nov 1, 11:11 pm, Omi Chiba  wrote:
> Thank you for understanding me :)
> I tried but this code will set the default value if the field exist on
> the view.
>
> I made a simple example. I don't want to show field2 so it's excluded
> in view using custom form but want to store the value like 'BBB' or
> 'CCC' before it's inserted into table. This code just leave field2
> blank...
>
> model
> 
> db.define_table('mytable',
>     Field('field1'),
>     Field('field2'))
>
> controller
> 
> def index():
>     form = SQLFORM(db.mytable)
>
>     form.vars.field2 = 'BBB'

This should work to pre-populate the value of field2 with 'BBB' but it
seems to be broken in 1.99.2

>
>     if form.process().accepted:
>         form.vars.field2 = 'CCC'

this has no effect, field2 will not be set to 'CCC' in the DB, the
insert has already been done at this point so field2 will be 'BBB' (if
it wasn't broken).
To change it you have to use onvalidation, see the example in the
book.

>         session.flash = 'form accepted'
>         redirect(URL('index'))
>     elif form.errors:
>         response.flash = 'form has errors'
>     return dict(form=form)
>
> view
> 
> {{extend 'layout.html'}}
>
> {{=form.custom.begin}}
> Field1: {{=form.custom.widget.field1}}
> {{=form.custom.submit}}
> {{=form.custom.end}}
>
> On Nov 1, 6:58 pm, pbreit  wrote:
>
>
>
>
>
>
>
> > I believe in your controller, before form.process() (or form.accepts),
> > include:
>
> > form.vars.FFTSCD = 'aaa'


[web2py] Re: Confused about hidden fields

2011-11-02 Thread apple
Instead of form.accepts() you can use form.validate() and then do your
own update. Then you do not need to pass unnecessary variables to the
view and back again.

form = SQLFORM(table, id)
if form.validate():
form.vars.mysecretvariable="whatever I want"
if not form.errors:
if not id:
id=table.insert(**dict(form.vars))
session.flash = "record inserted"
elif form.vars.get('delete_this_record',False):
db(table.id==id).delete()
session.flash = "record deleted"
else:
table[id].update_record(**dict(form.vars))
session.flash = "record updated"

On Nov 2, 3:11 am, Omi Chiba  wrote:
> Thank you for understanding me :)
> I tried but this code will set the default value if the field exist on
> the view.
>
> I made a simple example. I don't want to show field2 so it's excluded
> in view using custom form but want to store the value like 'BBB' or
> 'CCC' before it's inserted into table. This code just leave field2
> blank...
>
> model
> 
> db.define_table('mytable',
>     Field('field1'),
>     Field('field2'))
>
> controller
> 
> def index():
>     form = SQLFORM(db.mytable)
>
>     form.vars.field2 = 'BBB'
>
>     if form.process().accepted:
>         form.vars.field2 = 'CCC'
>         session.flash = 'form accepted'
>         redirect(URL('index'))
>     elif form.errors:
>         response.flash = 'form has errors'
>     return dict(form=form)
>
> view
> 
> {{extend 'layout.html'}}
>
> {{=form.custom.begin}}
> Field1: {{=form.custom.widget.field1}}
> {{=form.custom.submit}}
> {{=form.custom.end}}
>
> On Nov 1, 6:58 pm, pbreit  wrote:
>
>
>
>
>
>
>
> > I believe in your controller, before form.process() (or form.accepts),
> > include:
>
> > form.vars.FFTSCD = 'aaa'


[web2py] Re: Confused about hidden fields

2011-11-01 Thread Omi Chiba
Thank you for understanding me :)
I tried but this code will set the default value if the field exist on
the view.


I made a simple example. I don't want to show field2 so it's excluded
in view using custom form but want to store the value like 'BBB' or
'CCC' before it's inserted into table. This code just leave field2
blank...

model

db.define_table('mytable',
Field('field1'),
Field('field2'))

controller

def index():
form = SQLFORM(db.mytable)

form.vars.field2 = 'BBB'

if form.process().accepted:
form.vars.field2 = 'CCC'
session.flash = 'form accepted'
redirect(URL('index'))
elif form.errors:
response.flash = 'form has errors'
return dict(form=form)

view

{{extend 'layout.html'}}

{{=form.custom.begin}}
Field1: {{=form.custom.widget.field1}}
{{=form.custom.submit}}
{{=form.custom.end}}




On Nov 1, 6:58 pm, pbreit  wrote:
> I believe in your controller, before form.process() (or form.accepts),
> include:
>
> form.vars.FFTSCD = 'aaa'


[web2py] Re: Confused about hidden fields

2011-11-01 Thread pbreit
I believe in your controller, before form.process() (or form.accepts), 
include:

form.vars.FFTSCD = 'aaa'