On Sun, Jul 5, 2009 at 4:56 PM, Archer <dfdumar...@gmail.com> wrote:

>
> Ah - slide 72? Where would that be?
>
> On Jun 28, 8:01 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> > Actually the best way to customize forms is using the method explain
> > in slide 72 (slides are not atwww.web2py.com).
>

I think this meant to say "slides are _now at http://www.web2py.com";   - you
will need flash on your browser to see them; you can also download them from
the link (but need to register).


>
> >
> > Errormessages normally are inform.errors and they get displayed
> > below the corresponding widgets but you can do the following in views
> > for example:
> >
> > {{(errors,form.errors)=(form.errors,dict())}}
> >
> > so that errors are not displayed under widgets any more but stored in
> > a new "errors" dictionary. And you can display them as a you like:
> >
> > {{if 'name' in errors:}}Oops, there is no name here{{pass}}
> >
> > On Jun 28, 2:39 am, "jjahe...@googlemail.com"
> >
> > <jjahe...@googlemail.com> wrote:
> > > I have been playing around with web2py to see what I can do or not do.
> >
> > > I must say I like what I see. It seems very intuitive and easy to work
> > > with.
> >
> > > I am using windows XP SP3, python 2.5.4, web2py 1.64.4
> >
> > > It would seem that the default format for forms is to output them as
> > > tables.
> >
> > > So I have looked at usingCustomForms but continuing to use the
> > > validation system. I have picked up examples from various messages and
> > > modified them to see what I can do.
> >
> > > Thecustomforms work with the simple layout I have been using for my
> > > tests. But the one thing I have become stuck on at the moment is how I
> > > can change the position oferrormessages.
> >
> > > I have included the code I have been using. You can see how I have
> > > played around with using my ownformviews and addingformelements
> > > and widgets myself to see what happens. If you submit theform, it is
> > > validated and theerrormessages appear attached to eachformitem.
> >
> > > Ideally I would like to control where theerrormessages appear. But I
> > > have become brain dead. I must be overlooking something obvious. So I
> > > am checking to see if anyone can give me a pointer to what I can do.
> >
> > > One other point is that by default every element comes with a class
> > > name attached. I could just update each element and set the class to
> > > None to get rid of it. And if I need to I could then add my own class
> > > names. But from the point of view of keeping theformtidy, would it
> > > be useful to be able not to have default class names attached. Then I
> > > can avoid having to set each element off.
> >
> > > Here is the code. I hope the formatting stays good so you can read it.
> > > The model just has some menu code so I can see what I can do with
> > > menus. It works, but not sure if I have put it in the right place
> > > holder. I must admit I have not found too much info on menus.
> >
> > > Model
> >
> > > try:
> > >     from gluon.contrib.gql import *  # if running on Google App Engine
> > > except:
> > >     db = SQLDB('sqlite://storage.db')  # if not, use SQLite or other
> > > DB
> > > else:
> > >     db = GQLDB()  # connect to Google BigTable
> > >     session.connect(request, response, db=db)  # and store sessions
> > > there
> > >     # or use the following lines to store sessions in Memcache
> > >     #from gluon.contrib.memdb import MEMDB
> > >     #from google.appengine.api.memcache import Client
> > >     #session.connect(request, response, db=MEMDB(Client()))
> >
> > > response.menu = [
> > >      ['Index', False,
> > >       URL(request.application,'default','index')],
> > >       ['another', False,
> > >       URL(request.application,'default','another')],
> > >      ]
> >
> > > Controller
> >
> > > # # sample index page with internationalization (T)
> > > def index():
> > >     response.flash = T('Welcome to web2py')
> > >     return dict(message=T('Hello World'))
> >
> > > def form_factory(*a): return SQLFORM(SQLDB(None).define_table(*a))
> >
> > > #and now you can create a controller like the following
> >
> > > def formtest2():
> > >     options = ['Mr','Dr','Mrs','Ms']
> > >     options2 = ['New York','Boston','Baltimore']
> > >    form=form_factory('myform',
> > >            SQLField('name','string',requires=IS_NOT_EMPTY()),
> > >            SQLField('lastname','string',requires=IS_NOT_EMPTY()),
> > >            SQLField('address1','string',requires=IS_NOT_EMPTY()),
> > >            SQLField('address2','string',requires=IS_NOT_EMPTY()),
> > >            SQLField('test',requires=IS_IN_SET(options)),
> > >            SQLField('city',requires=IS_IN_SET(options2)),
> > >            SQLField('zip','string',requires=IS_NOT_EMPTY()))
> >
> > >     ifform.accepts(request.vars,session):
> > >         response.flash='formc accepted'
> > >         ### do something withform.vars, perhaps redirect somewhere
> > > else
> > >     elifform.errors:
> > >         response.flash='errors in formc'
> > >     else:
> > >         response.flash='please fill the formc again'
> > >     return dict(form=form, vars=form.vars)
> >
> > > View
> >
> > > {{extend 'layout.html'}}
> > > <h1>This is the default/formtest2.html template</h1>
> > >     <title>LayoutFormwithout Tables</title>
> > >     <style type="text/css">
> > >     .formLayout
> > >     {
> > >         background-color: #f3f3f3;
> > >         border: solid 1px #a1a1a1;
> > >         padding: 10px;
> > >         width: 300px;
> > >     }
> >
> > >     .formLayout label, .formLayout input
> > >     {
> > >         display: block;
> > >         width: 120px;
> > >         float: left;
> > >         margin-bottom: 10px;
> > >     }
> >
> > >     .formLayout label
> > >     {
> > >         text-align: right;
> > >         padding-right: 20px;
> > >     }
> >
> > >     br
> > >     {
> > >         clear: left;
> > >     }
> > >     </style>
> > > </head>
> > > <body>
> >
> > > <formaction="" enctype="multipart/form-data" method="post">
> > >     <div class="formLayout">
> > >     <h2>ContactForm</h2><br>
> > >         <label>Title</label>
> > >           {{=form.element(_name="test")}}<br>
> > >         <label>First Name</label>
> > >           {{=form.element(_name="name")}}<br>
> > >         <label>Last Name</label>
> > >           {{=form.element(_name="lastname")}}<br>
> > >         <label>Address</label>
> > >           {{form.element(_name="address1").update(_class=None)}}
> > >           {{=form.custom.widget.address1}}<br>
> > >         <label></label>
> > >           {{=form.element(_name="address2")}}<br>
> > >         <label>City</label>
> > >           {{=form.element(_name="city")}}<br>
> > >         <label>Zip</label>
> > >           {{=form.element(_name="zip")}}<br>
> > >           <div style="padding-left:7em">
> > >            <input type="submit" value="submit" ><br></div>
> > >     </div>
> > >    CUSTOM
> > >     {{=form.custom}}FIELDS
> > >     {{=form.fields}}
> > >     ERRORS
> > >     {{=form.errors}}
> > >     LAST
> > >           {{=form.custom.dspval.address1}}
> > >           {{=form.custom.inpval.address1}}<br>
> > >           {{=form.hidden_fields()}}
> > >     </form>
> > > </body>
> > > </html>
> >
> > > End of Code
> >
> > > I hope someone can give me a few pointers, or point out any obvious
> > > mistakes.
> >
> > > Regards
> >
> > > John Aherne
> >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to