the other part that is not work is when using select option, i can't insert 
the requires=IS_NOT_EMPTY()
do you have any idea about this?

thank you so much before

*1 testing results in controllers default.py : all work fine except the 
select option can't have requires because i generate it outside the form()*
def select_option():
    rows=db((db.product.quantity>0)).select(orderby=db.product.id, 
cache=(cache.ram, 10))
*    result="<select name='product' id='sale_product'><option 
value=''></option>"*
*    for row in rows:*
*        result += "<option value='" + str(row.id) + "'>" + 
row.product_name + "</option>"  *
*    result += "</select>"*
    return XML(result)

def sale():
    rows=db((db.product.quantity>0)).select(orderby=db.product.id, 
cache=(cache.ram, 10))

    form = FORM(TABLE( TR ( TH ( 'Product' ), TH ( 'Quantity' ), TH ( 
'Grand Total' ) ), 
                       TR ( TD ( select_option() ), 
                            TD ( INPUT (_id='sale_quantity', 
_name='quantity', _type='text', _value='', _size='3', requires = 
IS_NOT_EMPTY(error_message='cannot be empty!') ) ), 
                            TD ( INPUT (_id='sale_grand_total', 
_name='grand_total', _type='text', _value='', _size='3', requires = 
IS_NOT_EMPTY(error_message='cannot be empty!') ) ), 
                            TD ( INPUT (_type='submit', _value='Submit') ) 
) ) )
    if form.validate(session=None, formname='form'):
        if request.vars.product=="":
            response.flash = 'product can not be blank'
        elif request.vars.quantity=="":
            response.flash = 'quantity can not be blank'
        elif request.vars.quantity==0:
            response.flash = 'quantity can not be 0 value'
        else:
            import datetime
            import uuid
            invoice_no=str(datetime.date.today())+'-'+str(uuid.uuid4())
            product=db.product[request.vars.product]
            quantity=request.vars.quantity
            form.vars.id = db.sale.insert(invoice_no=invoice_no, 
                                          product=product.id, 
                                          quantity=quantity, 
                                          unit_price=product.unit_price,
                                          
total_price=int(quantity)*int(product.unit_price),
                                          
grand_total=request.vars.grand_total)
            response.flash = 'record inserted'
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)

*2 testing results in controllers default.py : an error occured when using 
for, it said invalid syntax*
def sale():
    rows=db((db.product.quantity>0)).select(orderby=db.product.id, 
cache=(cache.ram, 10))
    form = FORM(TABLE( TR ( TH ( 'Product' ), TH ( 'Quantity' ), TH ( 
'Grand Total' ) ), 
                       TR ( TD ( *SELECT ( OPTION ( _value='' ), OPTION ( 
_value='1', '1' ), *
*                                 for i,row in enumerate(rows): *
*                                    OPTION ( 'row.product_name', 
_value='row.id' ), *
*                                 _id='sale_product', _name='product' )* ), 
                            TD ( INPUT (_id='sale_quantity', 
_name='quantity', _type='text', _value='', _size='3', requires = 
IS_NOT_EMPTY(error_message='cannot be empty!') ) ), 
                            TD ( INPUT (_id='sale_grand_total', 
_name='grand_total', _type='text', _value='', _size='3', requires = 
IS_NOT_EMPTY(error_message='cannot be empty!') ) ), 
                            TD ( INPUT (_type='submit', _value='Submit') ) 
) ) )
    if form.validate(session=None, formname='form'):
        if request.vars.product=="":
            response.flash = 'product can not be blank'
        elif request.vars.quantity=="":
            response.flash = 'quantity can not be blank'
        elif request.vars.quantity==0:
            response.flash = 'quantity can not be 0 value'
        else:
            import datetime
            import uuid
            invoice_no=str(datetime.date.today())+'-'+str(uuid.uuid4())
            product=db.product[request.vars.product]
            quantity=request.vars.quantity
            form.vars.id = db.sale.insert(invoice_no=invoice_no, 
                                          product=product.id, 
                                          quantity=quantity, 
                                          unit_price=product.unit_price,
                                          
total_price=int(quantity)*int(product.unit_price),
                                          
grand_total=request.vars.grand_total)
            response.flash = 'record inserted'
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to