[web2py] Re: Validate the Checkbox
Thanks My problems are solved
[web2py] Re: Validate the Checkbox
Good tip Wikus.. you can also do the something similar with SQLFORM.factory and not define in the model (that way no DB table is created) in controller MY_OPTIONS = ["a","b","c"] form = SQLFORM.factory( Field("my_options", "list:string", default=MY_OPTIONS,widget=SQLFORM.widgets.checkboxes.widget, requires=[IS_IN_SET(MY_OPTIONS, multiple=True),IS_NOT_EMPTY()])) if form.accepts(request.vars): #code to process form return dict(form=form) On Feb 21, 4:03 pm, Wikus van de Merwe wrote: > The easiest way to do that is rely on web2py model -> form transformation > and use a validator (instead of the custom form). > > model > -- > MY_OPTIONS = ["a","b","c"] > db.define_table("my_table", > db.Field("my_options", "list:string", default=MY_OPTIONS)) > > db.my_table.my_options.widget = SQLFORM.widgets.checkboxes.widget > db.my_table.my_options.requires = [IS_IN_SET(MY_OPTIONS, multiple=True), > IS_NOT_EMPTY()] > > controller > -- > def my_function(): > if len(request.args): > form=SQLFORM(db.my_table, request.args[0]) > else: > form=SQLFORM(db.my_table) > > if form.accepts(request.vars): > redirect(URL(r=request, f='my_next_function', args=[form.vars.id])) > > return {"form":form}
[web2py] Re: Validate the Checkbox
The easiest way to do that is rely on web2py model -> form transformation and use a validator (instead of the custom form). model -- MY_OPTIONS = ["a","b","c"] db.define_table("my_table", db.Field("my_options", "list:string", default=MY_OPTIONS)) db.my_table.my_options.widget = SQLFORM.widgets.checkboxes.widget db.my_table.my_options.requires = [IS_IN_SET(MY_OPTIONS, multiple=True), IS_NOT_EMPTY()] controller -- def my_function(): if len(request.args): form=SQLFORM(db.my_table, request.args[0]) else: form=SQLFORM(db.my_table) if form.accepts(request.vars): redirect(URL(r=request, f='my_next_function', args=[form.vars.id])) return {"form":form}
Re: [web2py] Re: Validate the Checkbox
I got it but you are putted here the same name of the check box through which we can validate the multiple checkbox eaisly but here i want the value of the different check box in different variables for checking the multiple conditions. such as qury=db((db.employee.name==a ) | (db.employee.name==b ) | (db.employee.name==b )).select() On Tue, Feb 21, 2012 at 1:36 PM, whowhywhat wrote: > also > > > TR("Type:",TD(INPUT(_type="checkbox",_name="options",_value="a",_size="0",requires > = IS_NOT_EMPTY(error_message="Please select > at least one check-box"))," A" ... > > to have your required error message > > Please check out the excellent web2py documentation for forms and > validators http://web2py.com/books/default/chapter/29/7#Validators > > > On Feb 21, 12:51 pm, whowhywhat wrote: > > You can also just write a jquery validator for the same.. > > > > On Feb 21, 12:49 pm, whowhywhat wrote: > > > > > > > > > > > > > > > > > This should work. Although it is ugly (it gives a error message under > > > all the checkboxes :P ).. but does validate as you require. Please > > > check and let me know. > > > > > def multi_check_box(): > > > form = FORM(TABLE( > > > > > > TR("Type:",TD(INPUT(_type="checkbox",_name="options",_value="a",_size="0",requires > > > = IS_NOT_EMPTY())," A", > > > > > INPUT(_type="checkbox",_name="options",_value="b",_size="0")," B", > > > > > INPUT(_type="checkbox",_name="options",_value="c",_size="0")," C")), > > > TR("",INPUT(_type="submit",_value="SUBMIT" > > > if form.accepts(request.vars,session): > > > > > return dict(form=form) > > > > > On Feb 21, 11:09 am, Sanjeet Kumar wrote: > > > > > > > TR("Type:",(TD(INPUT(_type="checkbox",_name="a",_value="a",_size="0"),"A"))), > > > > > > (TD(INPUT(_type="checkbox",_name="b",_value="b",_size="0"),"B")), > > > > > > (TD(INPUT(_type="checkbox",_name="c",_value="c",_size="0"),"C"))), > > > > TR("",INPUT(_type="submit",_value="SUBMIT" )) > > > > > > On Tue, Feb 21, 2012 at 11:28 AM, whowhywhat > wrote: > > > > > please could post your controller code.. > > > > > > > On Feb 21, 10:32 am, Sanjeet Kumar wrote: > > > > > > I have the multiple check-box in one row in Controller I want to > validate > > > > > > it form controller when the user submit his request without > selecting any > > > > > > of the check-box than it should be shown the error message > "Please select > > > > > > at least one check-box" >
[web2py] Re: Validate the Checkbox
also TR("Type:",TD(INPUT(_type="checkbox",_name="options",_value="a",_size="0",requires = IS_NOT_EMPTY(error_message="Please select at least one check-box"))," A" ... to have your required error message Please check out the excellent web2py documentation for forms and validators http://web2py.com/books/default/chapter/29/7#Validators On Feb 21, 12:51 pm, whowhywhat wrote: > You can also just write a jquery validator for the same.. > > On Feb 21, 12:49 pm, whowhywhat wrote: > > > > > > > > > This should work. Although it is ugly (it gives a error message under > > all the checkboxes :P ).. but does validate as you require. Please > > check and let me know. > > > def multi_check_box(): > > form = FORM(TABLE( > > > TR("Type:",TD(INPUT(_type="checkbox",_name="options",_value="a",_size="0",requires > > = IS_NOT_EMPTY())," A", > > > INPUT(_type="checkbox",_name="options",_value="b",_size="0")," B", > > > INPUT(_type="checkbox",_name="options",_value="c",_size="0")," C")), > > TR("",INPUT(_type="submit",_value="SUBMIT" > > if form.accepts(request.vars,session): > > > return dict(form=form) > > > On Feb 21, 11:09 am, Sanjeet Kumar wrote: > > > > TR("Type:",(TD(INPUT(_type="checkbox",_name="a",_value="a",_size="0"),"A"))), > > > > (TD(INPUT(_type="checkbox",_name="b",_value="b",_size="0"),"B")), > > > > (TD(INPUT(_type="checkbox",_name="c",_value="c",_size="0"),"C"))), > > > TR("",INPUT(_type="submit",_value="SUBMIT" )) > > > > On Tue, Feb 21, 2012 at 11:28 AM, whowhywhat wrote: > > > > please could post your controller code.. > > > > > On Feb 21, 10:32 am, Sanjeet Kumar wrote: > > > > > I have the multiple check-box in one row in Controller I want to > > > > > validate > > > > > it form controller when the user submit his request without selecting > > > > > any > > > > > of the check-box than it should be shown the error message "Please > > > > > select > > > > > at least one check-box"
[web2py] Re: Validate the Checkbox
You can also just write a jquery validator for the same.. On Feb 21, 12:49 pm, whowhywhat wrote: > This should work. Although it is ugly (it gives a error message under > all the checkboxes :P ).. but does validate as you require. Please > check and let me know. > > def multi_check_box(): > form = FORM(TABLE( > > TR("Type:",TD(INPUT(_type="checkbox",_name="options",_value="a",_size="0",requires > = IS_NOT_EMPTY())," A", > > INPUT(_type="checkbox",_name="options",_value="b",_size="0")," B", > > INPUT(_type="checkbox",_name="options",_value="c",_size="0")," C")), > TR("",INPUT(_type="submit",_value="SUBMIT" > if form.accepts(request.vars,session): > > return dict(form=form) > > On Feb 21, 11:09 am, Sanjeet Kumar wrote: > > > > > > > > > TR("Type:",(TD(INPUT(_type="checkbox",_name="a",_value="a",_size="0"),"A"))), > > > (TD(INPUT(_type="checkbox",_name="b",_value="b",_size="0"),"B")), > > > (TD(INPUT(_type="checkbox",_name="c",_value="c",_size="0"),"C"))), > > TR("",INPUT(_type="submit",_value="SUBMIT" )) > > > On Tue, Feb 21, 2012 at 11:28 AM, whowhywhat wrote: > > > please could post your controller code.. > > > > On Feb 21, 10:32 am, Sanjeet Kumar wrote: > > > > I have the multiple check-box in one row in Controller I want to > > > > validate > > > > it form controller when the user submit his request without selecting > > > > any > > > > of the check-box than it should be shown the error message "Please > > > > select > > > > at least one check-box"
[web2py] Re: Validate the Checkbox
This should work. Although it is ugly (it gives a error message under all the checkboxes :P ).. but does validate as you require. Please check and let me know. def multi_check_box(): form = FORM(TABLE( TR("Type:",TD(INPUT(_type="checkbox",_name="options",_value="a",_size="0",requires = IS_NOT_EMPTY())," A", INPUT(_type="checkbox",_name="options",_value="b",_size="0")," B", INPUT(_type="checkbox",_name="options",_value="c",_size="0")," C")), TR("",INPUT(_type="submit",_value="SUBMIT" if form.accepts(request.vars,session): return dict(form=form) On Feb 21, 11:09 am, Sanjeet Kumar wrote: > TR("Type:",(TD(INPUT(_type="checkbox",_name="a",_value="a",_size="0"),"A"))), > > (TD(INPUT(_type="checkbox",_name="b",_value="b",_size="0"),"B")), > > (TD(INPUT(_type="checkbox",_name="c",_value="c",_size="0"),"C"))), > TR("",INPUT(_type="submit",_value="SUBMIT" )) > > > > > > > > On Tue, Feb 21, 2012 at 11:28 AM, whowhywhat wrote: > > please could post your controller code.. > > > On Feb 21, 10:32 am, Sanjeet Kumar wrote: > > > I have the multiple check-box in one row in Controller I want to validate > > > it form controller when the user submit his request without selecting any > > > of the check-box than it should be shown the error message "Please select > > > at least one check-box"
Re: [web2py] Re: Validate the Checkbox
TR("Type:",(TD(INPUT(_type="checkbox",_name="a",_value="a",_size="0"),"A"))), (TD(INPUT(_type="checkbox",_name="b",_value="b",_size="0"),"B")), (TD(INPUT(_type="checkbox",_name="c",_value="c",_size="0"),"C"))), TR("",INPUT(_type="submit",_value="SUBMIT" )) On Tue, Feb 21, 2012 at 11:28 AM, whowhywhat wrote: > please could post your controller code.. > > On Feb 21, 10:32 am, Sanjeet Kumar wrote: > > I have the multiple check-box in one row in Controller I want to validate > > it form controller when the user submit his request without selecting any > > of the check-box than it should be shown the error message "Please select > > at least one check-box" >
[web2py] Re: Validate the Checkbox
please could post your controller code.. On Feb 21, 10:32 am, Sanjeet Kumar wrote: > I have the multiple check-box in one row in Controller I want to validate > it form controller when the user submit his request without selecting any > of the check-box than it should be shown the error message "Please select > at least one check-box"