in

form.element(_name="reference").update(_type="hidden")

the update is invalid if the element returns None because no TAG has
_name='reference'.

Massimo

On Dec 28, 8:36 pm, Jon <[email protected]> wrote:
> One other question: it kept saying this function was invalid
> (.update):
>
> {{=form.element(_name="reference").update(_type="hidden")}}
>
> Can you tell me if the syntax is wrong? I see the value in making the
> type of some form elements "hidden", etc...!
>
> Jon
>
> On Dec 28, 6:22 pm, rfx_labs <[email protected]> wrote:
>
> >  Jon,
>
> > > If you use this successfully to build custom form(s) can you post a
> > > sample of your controller and view here?
>
> > Model:
> > proof=SQLDB("sqlite://proof.db")
>
> > proof.define_table('match',
> >                         SQLField('name'),
> >                         SQLField('min', 'integer'),
> >                         SQLField('intent'),
> >                         SQLField('keep_black', 'boolean'))
>
> > proof.define_table('color',
> >                         SQLField('name'),
> >                         SQLField('match', proof.match),
> >                         SQLField('extra')
> >                         SQLField('c', 'integer', default=0),
> >                         SQLField('m', 'integer', default=0),
> >                         SQLField('y', 'integer', default=0),
> >                         SQLField('k', 'integer', default=0),
> >                         SQLField('publish', 'boolean')
> >                         SQLField('preview'))
>
> > proof.color.name.requires=IS_NOT_EMPTY()
> > proof.color.match.requires=IS_IN_DB(proof, "match.id", "%(name)s",
> > orderby=proof.match.pos)
> > proof.color.extra.requires=IS_IN_SET(("Custom", "Option 2", "Option
> > 3"))
> > proof.color.c.requires=IS_INT_IN_RANGE(0,101)
> > proof.color.m.requires=IS_INT_IN_RANGE(0,101)
> > proof.color.y.requires=IS_INT_IN_RANGE(0,101)
> > proof.color.k.requires=IS_INT_IN_RANGE(0,101)
>
> > Controller:
> > def update():
> >         try:
> >                 rid    = int(request.args[0])
> >                 record = proof(proof.color.id==rid).select()[0]
> >         except:
> >                 session.flash=T('Entry doesn't exists!')
> >                 redirect(URL(r=request,f='index'))
>
> >         form=SQLFORM(proof.color, record, deletable=True)
>
> >         if form.accepts(request.vars,session):
> >                 redirect(URL(r=request, f='index'))
>
> >         return dict(form=form)
>
> > You see nothing special so long ;-)
>
> > view:
> > <form action="" enctype="multipart/form-data" method="post">
> >         <fieldset>
> >                 <legend>Generic</legend>
> >                 <ol>
> >                         <li><label 
> > for="color_name">Name:</label>{{=form.element
> > (_name="name")}}</li>
> >                         <li><label 
> > for="my_fancy_id">Color-Match:</label>{{=form.element
> > (_name="match").update(_id="my_fancy_id")}}</li>
> >                         <li><label 
> > for="color_extra">Name:</label>{{=form.element
> > (_name="extra")}}</li>
> >                 </ol>
> >         </fieldset>
> >         <fieldset>
> >                 <legend>Color values</legend>
> >                 <ol>
> >                 {{for elm in "cmyk":}}
> >                         <li><label for="color_{{=elm}}"><span 
> > id="c_{{=elm}}">
> > {{=elm.capitalize()}}:</span></label>{{=form.element(_name=elm)}}</li>
> >                         <!-- or write this better with helpers
> >                         {{=LI(LABEL(SPAN(elm.capitalize()+":", 
> > _id="c_"+elm),
> > _for="color_"+elm), form.element(_name=elm))}}
> >                         -->
> >                 {{pass}}
> >                 </ol>
> >         </fieldset>
> >         <fieldset>
> >                 <label for=color_publish>publish</label>{{=form.element
> > (_name="publish")}}
> >                 <label for="delete_record">Delete this 
> > color</label>{{=form.element
> > (_id="delete_record")}}
> >                 <input type="submit" value="save">
> >                 {{=form.element(_name="reference").update(_type="hidden")}}
> >                 {{=form.element(_name="id")}}{{=form.hidden_fields()}}
> >         </fieldset>
> > </form>
>
> > returns:
> > <form action="" enctype="multipart/form-data" method="post">
> >         <fieldset>
> >                 <legend>Generic</legend>
> >                 <ol>
> >                         <li><label for="color_name">Name:</label><input 
> > class="string"
> > id="color_name" name="name" type="text" value="Cyan" /></li>
> >                         <li><label 
> > for="my_fancy_id">Color-Match:</label><select
> > class="reference match" id="my_fancy_id" name="match"><option
> > selected="selected" value="1">Match 1</option><option value="2">Match
> > 2</option></select></li>
> >                         <li><label for="color_extra">Name:</label><select 
> > class="string"
> > id="color_extra" name="extra"><option value="Custom">Custom</
> > option><option value="Option 2">Option 2</option><option value="Option
> > 3">Option 3</option></select></li>
> >                 </ol>
> >         </fieldset>
> >         <fieldset>
> >                 <legend>Color values</legend>
> >                 <ol>
>
> >                         <li><label for="color_c"><span 
> > id="c_c">C:</span></label><input
> > class="integer" id="color_c" name="c" type="text" value="0" /></li>
> >                         <!-- or write this better with helpers
> >                         <li><label for="color_c"><span 
> > id="c_c">C:</span></label><input
> > class="integer" id="color_c" name="c" type="text" value="0" /></li>
> >                         -->
>
> >                         <li><label for="color_m"><span 
> > id="c_m">M:</span></label><input
> > class="integer" id="color_m" name="m" type="text" value="28" /></li>
> >                         <!-- or write this better with helpers
> >                         <li><label for="color_m"><span 
> > id="c_m">M:</span></label><input
> > class="integer" id="color_m" name="m" type="text" value="28" /></li>
> >                         -->
>
> >                         <li><label for="color_y"><span 
> > id="c_y">Y:</span></label><input
> > class="integer" id="color_y" name="y" type="text" value="100" /></li>
> >                         <!-- or write this better with helpers
> >                         <li><label for="color_y"><span 
> > id="c_y">Y:</span></label><input
> > class="integer" id="color_y" name="y" type="text" value="100" /></li>
> >                         -->
>
> >                         <li><label for="color_k"><span 
> > id="c_k">K:</span></label><input
> > class="integer" id="color_k" name="k" type="text" value="0" /></li>
> >                         <!-- or write this better with helpers
> >                         <li><label for="color_k"><span 
> > id="c_k">K:</span></label><input
> > class="integer" id="color_k" name="k" type="text" value="0" /></li>
> >                         -->
>
> >                 </ol>
> >         </fieldset>
> >         <fieldset>
> >                 <label for=color_publish>publish</label><input 
> > class="boolean"
> > id="color_publish" name="publish" type="checkbox" value="on" />
> >                 <label for="delete_record">Delete this color</label><input
> > class="delete" id="delete_record" name="delete_this_record"
> > type="checkbox" value="on" />
> >                 <input type="submit" value="save">
> >                 <input class="reference reference" id="color_reference"
> > name="reference" type="hidden" value="5" />
> >                 <input name="id" type="hidden" value="4" /><input 
> > name="_formkey"
> > type="hidden" value="815a1592-f25e-4a25-af72-78ebedced385" /><input
> > name="_formname" type="hidden" value="color" />
> >         </fieldset>
> > </form>
>
> > I hope you get an idea.
>
> > The benefits:
> > - only once define requires for appadmin and your custom forms in the
> > model
> > - handling of field values and errors is done from SQLFORM()
> > - No need to adjust class or id in controller
>
> > Martin
--~--~---------~--~----~------------~-------~--~----~
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