On Thursday, July 13, 2017 at 6:26:07 PM UTC-7, 黄祥 wrote:
>
> yes, thanks for the hints lionel, the show_if works, but the requires part 
> that depend on another form field is still not work.
> no error occured, but the form validation is not work.
> i've create another simple webapp too but still got the same (before use 
> is_in_db() that refer to another table, the new webapp is simpler just use 
> is_in_set() )
> *e.g. *
> *models/db.py*
> db.define_table('test', 
> Field('field0', requires = IS_IN_SET([1, 2] ) ),
> Field('field1'),
> format = '%(field0)s')
>
> *controllers/default.py*
> def test():
> * if request.vars.field0 == 1:*
> * #if request.post_vars.field0 == 1:*
> * #if db.test.field0 == 1:*
> * db.test.field1.requires = IS_NOT_EMPTY()*
>
> fields = ['field0', 'field1']
> form = SQLFORM(db.test, fields = fields)
> if form.validate():
> db.test.insert(**db.test._filter_fields(form.vars) )
> return dict(form = form)
>
> what i expected, when user select the 1, the field2 will give a 
> form.field2.error indicate that the field2 must be filled
> the above code not give an error, it just input to the table, wheter the 
> choice is 1 or 2.
> is there any way to fix this using web2py way?
>
> thanks and best regards,
> stifan
>


Way late on this, but I think you want to use something like
def test():
  if form.process(onvalidation=ck_my_field0).accepted:

def ck_my_field0(form):
  [...]



At first, this section of the book looks like it might apply:
<URL:http://web2py.com/books/default/chapter/29/07/forms-and-validators#Validators-with-dependencies>
but it seems not to have anything for when another field has a specific 
value.  IS_EQUAL_TO() doesn't work for that.

/dps

-- 
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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to