Ok, if I am understanding correctly you want a complex validation. I mean validating a field base on the input of an other field. Default web2py validator are applying only to one field at a time. It is possible to do what you ask for, but it will require that you implement your own validator. You can have a look into gluon/validators.py to figure out where to start.
I use to modify some of the web2py validator in the pass to make sure that only one FK is provided for a table where to kind of relation was used cause by a bad design. Check validators.py and if you still want to make complex validation I could help a little bit. Richard On Wed, Mar 21, 2012 at 4:30 PM, Rakesh Singh <rak...@verifaction.co.za>wrote: > Hi Richard, > > My tables are pretty large (30-60 columns each), so let me use another > test table. > > Let's say we have a table called survey. > If the user selects "Male" in the "Sex" field, "Favourite Car" and > "Favourite Sport" must not be empty. > "Favourite Perfume" and "Favourite Soapie" can be empty. > If the user selects "Female" then the opposite applies. > > I was initially trying to hide the fields, and only unhide the > appropriate ones bases on the user input. > But it is not necessary. I don't mind displaying all fields, as long > as they are validated based on user input. > > > I initially tried SQLFORM.grid and smartgrid, but what I want to > achieve does not seem possible. > I thought of splitting the input form into multiple forms, but due to > the number of conditions, it won't be feasible to the user. > > Thank you for any advice/suggestions. > > Regards, > > Rakesh > > > #-- TABLE DEFINITION > db.define_table('survey', > Field('fname', > 'string', > length=25, > required=True, > requires=[IS_NOT_EMPTY(), IS_UPPER()], > label='First Name'), > Field('sname', > 'string', > length=80, > required=True, > requires=[IS_NOT_EMPTY(), IS_UPPER()], > label='Surname'), > Field('sex', > 'string', > length=1, > required=True, > requires=[IS_NOT_EMPTY(), IS_UPPER(), IS_IN_SET(['F', 'M'])], > label='Sex'), > Field('fav_perfume', > 'string', > length=20, > required=False, > requires=IS_UPPER(), > label='Favourite Perfume'), > Field('fav_soapie', > 'string', > length=20, > required=False, > requires=IS_UPPER(), > label='Favourite Soapie'), > Field('fav_car', > 'string', > length=20, > required=False, > requires=IS_UPPER(), > label='Favourite Car'), > Field('fav_sport', > 'string', > length=20, > required=False, > requires=IS_UPPER(), > label='Favourite Sport') > ) > > > > On Mar 20, 11:46 am, Richard Vézina <ml.richard.vez...@gmail.com> > wrote: > > We will need more code to help you... > > > > Regards > > > > Richard > > > > On Tue, Mar 20, 2012 at 10:15 AM, Rakesh Singh <rak...@verifaction.co.za > >wrote: > > > > > > > > > > > > > > > > > Hi All, > > > > > Apologies if this has been covered before but I cannot seem to find the > > > appropriate solution in the archives or in the web2py book. > > > > > I am using SQLFORM.grid to generate an interface into my table. > > > Some of my fields in the table are only required based on other inputs. > > > As a simple example, if the user is an individual, the Identity Number > > > field must be completed. > > > But if it is a business, the Company Registration Number field must be > > > completed. > > > > > I read the Conditional Field section in the book, but I cannot seem to > get > > > it to work on my form. > > > Also, my table name and columns have quite a few underscores, so I'm > not > > > sure if this is affecting the jQuery syntax. > > > eg. NCS_SARS_DECLARANT is the table, RECORD_TYPE is the column > > > If I understand correctly, I should have : > > > jQuery('#NCS_SARS_DECLARANT_RECORD_TYPE__row').hide() ? > > > > > What is the suggested way in achieving this? > > > > > Many thanks. > > > > > Regards, > > > > > Rakesh > > > > > Running Web2py Version 1.99.7 >