What i want to achieve is to disable the quantity button in my shopping
application that allows buyers to select the number of items they want if
their number exceeds the number of available items. In my mind I can only
achieve this if i were able to check first the quantity of the items we
have and if they are not smaller than the client's requested amount as the
client is still in the process of buying while clicking the quantity
button, I am not sure on how to achieve this!
*VIEW*
<style>
.disabled {
opacity: 0.65;
cursor: not-allowed;
}
</style>
<h7 class="amt {{='red' if p.amount<=5 else ''}}">{{=p.amount}} available
in stock</h7>
<h5>
<span style="color: aqua; font-weight: bold;">
{{=MoneyFormat(p.price)}}</span>
</h5>
<img id="item" class="magnify" src="{{=URL('download',args=p.image)}}"
height="200px"/>
<br />
{{=A('Remove',callback=URL('cart_callback',vars=dict(id=p.id,action='sub')),target='item%s'%p.id,_class='button
pill')}} - <span id="{{='item%s'%p.id}}" style="font-weight: bold; color:
red;">{{=session.cart.get(p.id,0)}}</span> in cart -
*<span class="{{='disabled' if p.amount > 'item%s'%p.id else
''}}">{{=A('Add to
cart',callback=URL('cart_callback',vars=dict(id=p.id,action='add')),target='item%s'%p.id,_class='button
pill')}}</span>*
The highlighted part is where the button span should be getting disabled if
the condition is satisfied the problem is i have not figured out a way to
check first if the client's amount is higher than what we have in our stock!
*CART_CALLBACK FUNCTION*
The cart_callback function is the one that counts the number of items and
adds them to the cart as the client clicks the button
def cart_callback():
id = int(request.vars.id)
if request.vars.action == 'add':
session.cart[id]=session.cart.get(id,0)+1
if request.vars.action == 'sub':
session.cart[id]=max(0,session.cart.get(id,0)-1)
return str(session.cart[id])
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/60e3aab7-3174-4649-ad9a-94d6abad1c2c%40googlegroups.com.