Hi Cyber,

Sorry for delay, I have been busy all day.

Good question, I overlooked the fact that you had multiple records.  I
was reading too fast!  This is a more tricky problem.

Below are some code snippets from some working code that I have which
displays and updates multiple records.  I am updating a 'price' field
here.  I appreciate that this is not a solution for your exact
requirement, but I hope that this might inspire you towards finding
that solution  :-)

Regards, David

---- controller ------
myrecords=db(query).select(db.table.ALL)
if form.accepts ...
    for r in myrecords:
        if request.vars.has_key('id%i_price' % r.table.id):
            r.table.update_record(price=request.vars['id%i_price'%
r.table.id])

----- view ------
<table>....
{{for record in myrecords:}}
  <tr>
    <td>{{=record.carprice.id}}</td>
    <td><INPUT type="text", name="id{{=record.table.id}}_price",
value={{=record.table.price}}/></td>
  </tr>
{{pass}}
...</table>


On Mar 14, 9:49 pm, cyber <vlad.mul...@gmail.com> wrote:
> Any piece of advise, please!
>
> How can I update each row by changing checkbox states?
>
> {{for nums in table:}}
> {{=TR(
>     TD(nums.id),
>     TD(nums.num),
>     TD(nums.name),
>     TD(nums.dtime),
>     TD(INPUT(_type='checkbox',value=nums.enter)),
>     TD(A(nums.enter_d,_href=URL('index'))),
>     TD(INPUT(_type='checkbox',value=nums.idk)),
>     TD(A(nums.idk_d,_href=URL('index'))),
>     TD(INPUT(_type='checkbox',value=nums.svh)),
>     TD(A(nums.svh_d,_href=URL('index'))),
>     TD(INPUT(_type='checkbox',value=nums.reg)),
>     TD(A(nums.reg_d,_href=URL('index'))),
>     TD(INPUT(_type='checkbox',value=nums.out)),
>     TD(A(nums.out_d,_href=URL('index'))))
>
> }}
>
> How should I use SQLFORM update in this case?
> *****************************************************
>
> On 14 мар, 15:51, cyber <vlad.mul...@gmail.com> wrote:
>
> > How can I get current row id to update it?
> > *******************************************
>
> > On 13 мар, 04:04, villas <villa...@gmail.com> wrote:
>
> > > Do you need a custom form?  How about...
> > > Use SQLFORM with 'keepvalues'. When user clicks checkbox, submit form
> > > with jQuery.
> > > Once that's working experiment with submitting form with ajax.
>
> > > On Mar 12, 8:15 pm, cyber <vlad.mul...@gmail.com> wrote:
>
> > > > I have few fields in db like this one:
> > > >    Field('enter', 'boolean', default=False)
>
> > > > And I made new page with selection result:
> > > >    def table():
> > > >        table=db().select(db.autos.ALL, orderby=~db.autos.dtime)
> > > >        return dict(table=table)
>
> > > > Then I wrote code for this new page to represent data from my db:
> > > >     <form>
> > > >     {{for nums in table:}}
> > > >     {{=TR(TD(nums.num),
> > > >     TD(nums.name),
> > > >     TD(nums.dtime),
> > > >     TD(INPUT(_type="checkbox",value=nums.enter)),
> > > >     TD(nums.enter_d),
> > > >     TD(INPUT(_type="checkbox",value=nums.idk)),
> > > >     TD(nums.idk_d),
> > > >     TD(INPUT(_type="checkbox",value=nums.svh)),
> > > >     TD(nums.svh_d),
> > > >     TD(INPUT(_type="checkbox",value=nums.reg)),
> > > >     TD(nums.reg_d),
> > > >     TD(INPUT(_type="checkbox",value=nums.out)),
> > > >     TD(nums.out_d))}}
> > > >     {{pass}}
> > > >     </form>
>
> > > > So, the matter is: how can I change checkboxes state and automaticaly
> > > > update table in db?
> > > > Can I add some action when user changes checkboxes state?
> > > > ***************************************************************************
> > > >  **************
>
> > > > On 11 мар, 12:53, cyber <vlad.mul...@gmail.com> wrote:
>
> > > > > It works perfectly!
> > > > > I understood your code. Many thanks and respects for you!!!
>
> > > > > ***
>
> > > > > Could you give me a piece of advise of how can I use checkboxes to
> > > > > represent results of db selection?
> > > > > I have some boolean fields in db and I want users to be able to check/
> > > > > uncheck checkbox's state. Is it posible?
>
> > > > > **************************************************************
>
> > > > > On 10 мар, 17:47, DenesL <denes1...@yahoo.ca> wrote:
>
> > > > > > After an insert, form.vars.id will have the new record's id.
>
> > > > > > But to avoid another DB access you can make the changes before the
> > > > > > record is written using the onvalidation parameter in the accepts.
>
> > > > > > @auth.requires_login()
> > > > > > def new():
> > > > > >     def set_name(form):
> > > > > >         form.vars.name=author
> > > > > >         return
> > > > > >     form = SQLFORM(db.autos, fields=['num'],
> > > > > >            labels={'num':'Number'},
> > > > > >            submit_button='GO',
> > > > > >            formstyle='divs')
> > > > > >     if form.accepts(request.vars, session,
> > > > > >             onvalidation=set_name):
> > > > > >         response.flash = 'Yoh-ho-ho!'
> > > > > >     elif form.errors:
> > > > > >         response.flash = 'Bad-bad-bad!'
> > > > > >     else:
> > > > > >         response.flash = 'Fill the form'
> > > > > >     return dict(form=form)
>
> > > > > > On Mar 10, 5:56 am, cyber <vlad.mul...@gmail.com> wrote:
>
> > > > > > > The code in controller:
> > > > > > > @auth.requires_login()
> > > > > > > def new():
> > > > > > >     author=auth.user.username
> > > > > > >     form = SQLFORM(db.autos, fields=['num'], 
> > > > > > > labels={'num':'Number'},
> > > > > > > submit_button='GO', formstyle='divs')
> > > > > > >     if form.accepts(request.vars, session):
> > > > > > >         response.flash = 'It's OK!'
> > > > > > >     elif form.errors:
> > > > > > >         response.flash = 'There is an error!'
> > > > > > >     else:
> > > > > > >         response.flash = 'Fill the form!'
> > > > > > >     rows=db(db.autos.id>0).select()
> > > > > > >     last_row=rows[-1]
> > > > > > >     last_row.update_record(name=author)
> > > > > > >     return dict(form=form)
>
> > > > > > > *******************************
> > > > > > > And the model piece of code is:
> > > > > > > import datetime
> > > > > > > now=datetime.datetime.today()
> > > > > > > db.define_table('autos',
> > > > > > >     Field('num', length=8),
> > > > > > >     Field('name'),
> > > > > > >     Field('dtime', 'datetime', default=now),
> > > > > > >     Field('enter', 'boolean', default=False),
> > > > > > >     Field('enter_d'),
> > > > > > >     Field('idk', 'boolean', default=False),
> > > > > > >     Field('idk_d'),
> > > > > > >     Field('svh', 'boolean', default=False),
> > > > > > >     Field('svh_d'),
> > > > > > >     Field('reg', 'boolean', default=False),
> > > > > > >     Field('reg_d'),
> > > > > > >     Field('out', 'boolean', default=False),
> > > > > > >     Field('out_d')
> > > > > > >     )
>
> > > > > > > *****************
> > > > > > > And view file is:
> > > > > > > {{extend 'layout.html'}}
> > > > > > > {{=form}}
>
> > > > > > > So, I want user to enter only value 'num' in db.autos.
> > > > > > > But user_name (for current user) and date_time info have to be 
> > > > > > > updated
> > > > > > > automaticly after user presses "GO" button.
> > > > > > > Could you check my code? Is it correct?
>
> > > > > > > On 9 мар, 17:27, DenesL <denes1...@yahoo.ca> wrote:
>
> > > > > > > > Can you show us your current code?.
>
> > > > > > > > On Mar 9, 9:03 am, cyber <vlad.mul...@gmail.com> wrote:
>
> > > > > > > > > Hi
>
> > > > > > > > > How can I update new (just created) record in the table?
> > > > > > > > > Table consists of several fields but in the form page user 
> > > > > > > > > have to
> > > > > > > > > enter only one value for one row.
> > > > > > > > > So, I need insert in the current row not only this value but 
> > > > > > > > > user name
> > > > > > > > > and datetime.
> > > > > > > > > I can insert first value but I have no idea of how to auto 
> > > > > > > > > update new
> > > > > > > > > row with required values.
>
> > > > > > > > > Any ideas?
>
>

Reply via email to