Re: [web2py:4893] validations: IS_NOT_IN_DB prevents resubmit?

7 views
Skip to first unread message
Message has been deleted

Massimo Di Pierro

unread,
May 15, 2008, 11:47:53 PM5/15/08
to web...@googlegroups.com
EDIT FOR:

form=SQLFORM(db.person)

UPDATE FORM:

record=db(db.person.id==....).select()[0]
form=SQLFORM(db.person,record)

I guess you can combine them if this is what you are trying to do
(not sure it is a good idea)

records=db(db.person.name==request.vars.name).select()
form=SQLFORM(db.person,records[0] if len(records) else None)


On May 15, 2008, at 10:21 PM, g-man wrote:

>
> I can create my record with no problem...
>
> db.define_table('person', SQLField('name'))
> db.person.name.requires=IS_NOT_IN_DB(db, 'person.name')
>
> But, when I visit it on an edit form and try to 'Submit' with no
> change, web2py sees the original value in the database, thinks my
> 'Submit' is an attempt to create a new record with the same field
> value, and thus rejects the action.
>
> In other words, my field gets frightened of its own reflection in the
> mirror!
>
> What I need is a way to say, 'If this is an update of a record, it's
> OK to have the same value for a field.'
>
> How do I allow a no-change update in an existing field?
> >

g-man

unread,
May 16, 2008, 9:03:05 PM5/16/08
to web2py Web Framework
Hi Massimo,

I actually canceled this post and reposted with a new subject line as
soon as I discovered the true problem, which happens only in the
IS_NULL_OR(IS_NOT_IN_DB(...)) case; otherwise it works perfectly.

My code looks exactly like yours, except the first function is named
NEW, and the second EDIT. For DRY purposes (because they look
identical: {{=form}}), I would eventually like them to share the same
view, but that's in the future.

I'll do some more experiments, but perhaps there is a way to validate
only other OTHER records with the same field, not reflexivly?

g

Massimo Di Pierro

unread,
May 16, 2008, 9:15:36 PM5/16/08
to web...@googlegroups.com
I am sorry, I am not sure I understand the problem. Could you post a
more detailed example and I will run it?

Massimo

Massimo Di Pierro

unread,
May 16, 2008, 11:28:47 PM5/16/08
to web...@googlegroups.com
I read you email again and I understood the problem. I fixed it in
trunk. Please give it a try. 226

Massimo

Reply all
Reply to author
Forward
0 new messages