Thank you for your detailed reply.  I hope I'm not opening a can of
worms.

Being a relative newbie to both Python and Web2py, reading your
explanation makes sense to my elementary level.  wish I had a higher
lever of Python competence.   What I don't understand is, with the
exception of formatting (additional cr's and indentation), the
generated html code is the same as the custom html code.  Without
additional code embedded in the form, how would the 'hasattr' be
satisfied by the {{=form}} but not the custom html?

Thanks,
Gary


On May 3, 4:09 pm, dlypka <dly...@gmail.com> wrote:
> The idea of replacing the handcoded <input> tag by a call to a
> framework 'control'
> is basically parallel to the situation when coding a ASP.NET page:
> the developer has to choose between
>   hand-coding an <input> tag
>   OR
>   coding an ASP.NET control, which in this case would be <ASP:TextBox
> id="myTextBox" name="myTextBoxName" ...
>
> Most developers would choose the <ASP:TextBox> because it has enhanced
> functionality provided by .NET, beyond what <input> provides.
>
> So basically, the INPUT class here is what would be called a 'control'
> in ASP.NET.
>
> So looks like it would be usefully to formally define the concept of
> web2py 'controls'..
> Maybe we could use another word instead of 'control'  - maybe
> 'wig2py'?
>
> 'wig2py' would be a subframework of widgets within web2py which can be
> directly embedded in the markup
> and which in most cases can replace standard html tags to provide
> enhanced functionality such as working
> with the CRUD code to provide automatic field - level error messages.
>
> On May 3, 3:51 pm, dlypka <dly...@gmail.com> wrote:
>
> > Since generating forms thru those HTML class methods is not too much
> > fun,
> > I believe we could continue along your solution path by making some
> > changes
> > to those classes so that we can create an instance of class INPUT to
> > generate ONLY the input tags
> > So in this scenario you would slightly change your markup to just
> > replace the handcode <input> tags by something like
> > {{ INPUT(_type='text',_name='name',value='Max').xml()}}
>
> > On May 3, 3:36 pm, dlypka <dly...@gmail.com> wrote:
>
> > > OK I found it (I believe) in (assuming you have downloaded the web2py
> > > sourcecode)
>
> > > \web2py\gluon\html.py   line 744:
>
> > >     def xml(self):
> > >         name = self.attributes.get('_name', None)
> > >         if name and hasattr(self, 'errors') and self.errors.get(name,
> > >                 None):
> > >             return DIV.xml(self) + DIV(self.errors[name],
> > > _class='error', errors=None, _id='%s__error' % name).xml()
> > >         else:
> > >             return DIV.xml(self)
>
> > >       So it looks like we must satisfy
> > >               hasattr(self, 'errors')
>
> > > But it looks like all this code is part of
> > > class INPUT(DIV):
>
> > > So it looks like you must generate the form using those HTML function
> > > calls if you want that error code to kick in.
> > > I guess that when the auto CRUD is used, it uses these HTML classes to
> > > generate the form and so that is why the error message works in that
> > > case.
>
> > > On May 3, 2:51 pm, Gary <gary.k.ma...@gmail.com> wrote:
>
> > > > Thanks to all for your input and suggestions.  I've tried to make the
> > > > changes without effecting the functionality or the goal of using the
> > > > 'crud' controllers.
>
> > > > Massimo - I'll repost the application with the changes below.
>
> > > > Alvaro - I've considered abandoning the use of the crud controllers
> > > > and use 'form', but I've gone this far and it has become a challenge,
> > > > plus I hope to add to the knowledge base about the use of the crud
> > > > code.
>
> > > > dlypka - I've taken your suggestion and (essentially) copied the code
> > > > from the {{=form}} to be as sure as I could to duplicate the layout
>
> > > > John - I've incorporated the form.custom.inpval.  When I looked at
> > > > what was generated by {{=form}} it didn't seem to need the form
> > > > action.  I may be missing something, but everything works except the
> > > > response.error display, so I'm a little confused.  Massimo has asked
> > > > to see the updated version of the code, so I'll let him take a look
> > > > before I add too much more.
>
> > > > Here is the MVC.  The view contains both custom code and {{=form}}.
> > > > It doesn't make any difference which input fields or submit button is
> > > > used, the data is handled properly.  The problem is, if you leave
> > > > 'testfield1' blank, only the {{=form}} version displays the 'cannot be
> > > > empty' message.  The error is not displayed in the custom form.  The
> > > > code for the labels and fields are copied directly from the {{=form}}
> > > > source of the page and modified to display the
> > > > form.custom.inpval.fieldname variables.
>
> > > > 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
> > > > ##
> > > > db.define_table('testtable',SQLField('testfield1','string'),SQLField
> > > > ('testfield2','string'))
> > > > db.testtable.testfield1.requires=IS_NOT_EMPTY()
>
> > > > from gluon.tools import Mail, Auth, Crud     # new in web2py 1.56
> > > > auth=Auth(globals(),db)                      # authentication/
> > > > authorization
> > > > auth.define_tables()                         # creates all needed
> > > > tables
> > > > crud=Crud(globals(),db)                      # for CRUD helpers using
> > > > auth
> > > > crud.settings.update_next = URL(r=request, f='index')
>
> > > > Controller
> > > > ------------
> > > > def index():
> > > >     session.action = ""
> > > >     redirect(URL(r=request,f='testdata'))
>
> > > > @auth.requires_login()
> > > > def testdata():
> > > >     setsubmit()
> > > >     if request.args: id = request.args[0]
> > > >     else: id = 3   # Included for testing
> > > >     if session.action == "create":
> > > >         return dict(form=crud.create(db.testtable))
> > > >     elif session.action == "update":
> > > >         return dict(form=crud.update(db.testtable,id))
> > > >     else:
> > > >         return dict(form=crud.read(db.testtable,id))
>
> > > > def setsubmit():
> > > >     if request.vars.submit1: session.action = "create"
> > > >     if request.vars.submit2: session.action = "update"
> > > >     if request.vars.submit3: session.action = ""
>
> > > > def data():
> > > >     response.view="%s/%s/%s.html" %
> > > > (request.controller,request.function, request.args[0])
> > > >     return dict(form=crud())
>
> > > > def user():
> > > >     return dict(form=auth())
>
> > > > Views
> > > > ------
> > > > ( The following is default/testdata.html )
>
> > > > {{extend 'layout.html'}}
> > > >  <h1>Testdata
> > > > {{if session.action == "update":}}
> > > > Update
> > > > {{elif session.action == "create":}}
> > > > Add
> > > > {{pass}}
> > > > </h1>
> > > > {{=form}}
> > > > =======================================
> > > > <form action="" enctype="multipart/form-data" method="post">
> > > > <table>
> > > > <tr id="testtable_testfield1__row">
> > > >     <td><label for="testtable_testfield1"
> > > > id="testtable_testfield1__label">Testfield1: </label></td>
> > > >     {{if session.action in ["update","create"]:}}
> > > >     <td><input class="string" id="testtable_testfield1"
> > > > name="testfield1" type="text"
> > > > value="{{=form.custom.inpval.testfield1}}" /></td>
> > > >     {{else:}}
> > > >     <td>{{=form.custom.inpval.testfield1}}</td>
> > > >     {{pass}}
> > > >     <td></td>
> > > > </tr>
> > > > <tr>
> > > >     <td><label >Testfield2:</label></td>
> > > >     {{if session.action in ["update","create"]:}}
> > > >     <td><input class="string" id="testtable_testfield2"
> > > > name="testfield2" type="text"
> > > > value="{{=form.custom.inpval.testfield2}}" /></td>
> > > >     {{else:}}
> > > >     <td>{{=form.custom.inpval.testfield2}}</td>
> > > >     {{pass}}
> > > >     <td></td>
> > > > </tr>
> > > > {{if session.action == "update":}}
> > > > <tr id="delete_record__row">
> > > >     <td><label for="delete_record" id="delete_record__label">Check to
> > > > delete:</label></td>
> > > >     <td><input class="delete" id="delete_record"
> > > > name="delete_this_record" type="checkbox" value="on" /></td>
> > > >     <td></td>
> > > > </tr>
> > > > {{pass}}
> > > > </table>
> > > > {{include 'buttons.html'}}
>
> > > > ( The following is buttons.html)
>
> > > > <br />
> > > > {{if session.action in ["update","create"]:}}
> > > >     <input type="submit" name="submit" value="Submit" />
> > > >     <input type="submit" name="submit3" value="Cancel" />
> > > > {{else:}}
> > > >     <input type="submit" name="submit1"
> > > > value="&nbsp;&nbsp;Add&nbsp;&nbsp;&nbsp;" />
> > > >     <input type="submit" name="submit2" value="Update" />
> > > >     <input type="submit" name="submit3" value="Cancel" />
> > > > {{pass}}
> > > > {{=form.hidden_fields()}}
>
> > > > ++++++++++++++ End of MVC ++++++++++++++++++++
>
> > > > Thanks again to all.
>
> > > > Regards,
> > > > Gary- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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