Yebach
Yebach

Reputation: 1691

web2py SQLFORM.grid () get field values on process

on my edit/add page for SQLFORM.grid I would like to get the values of some fields on process. In case this value in combination with another field (userid) already exists user has to be notified about it.

any suggestions?

Upvotes: 0

Views: 422

Answers (1)

Anthony
Anthony

Reputation: 25536

You can simply define the validator for one of the fields so it doesn't allow duplicates when the other field is also a duplicate, and then let the standard form validation process handle everything:

db.define_table('mytable',
    Field('userid', 'reference auth_user'),
    Field('otherfield',
          requires=IS_NOT_IN_DB(db(db.mytable.userid == request.vars.userid),
                                'mytable.otherfield')))

Whenever a form is submitted, the IS_NOT_IN_DB validator will return an error if the value of "otherfield" is duplicated among the set of records where "userid" is also duplicated.

Upvotes: 1

Related Questions