[web2py] Re: Is there something like an "optional requires"
You can file a request for improvement. This cannot be changed without hitting the db twice: to validate the field to update the options. Right now we ask that is done explicitly. On Oct 21, 12:02 pm, Calycé wrote: > That's exactly what I'm experiencing. Do I need to file a bug ? > > On Oct 21, 4:11 pm, Anthony wrote: > > > > > > > > > I *think* if you submit a form and immediately reload a new form (as part of > > the same action), the new form's dropdown is populated (via the IS_IN_DB > > validator) before the db insert of the submitted form, so the new form > > doesn't have the most up-to-date set of values. If that's the case, it > > should probably be fixed. > > > On Friday, October 21, 2011 9:28:38 AM UTC-4, Calycé wrote: > > > > Thanks a lot to both of you the IS_EMPTY_OR() was indeed what I was > > > needing (note to self: reread the book...) > > > > Could anyone of you tell me when the the combo is populated ? I'm just > > > asking because now, when I enter a record using the appadmin > > > interface, the new record is not appearing in the combo but is > > > correctly inserted in the table. I have to reload the page in order to > > > see the last inserted category in the combo. > > > > For the "0 or" it's a bad cut 'n paste... my bad. > > > > On Oct 21, 2:56 pm, DenesL wrote: > > > > Hi Calycé, > > > > > note that: > > > > store.category.parent_category.requires = 0 or IS_IN_DB(db, > > > > db.category.id, '%(name)s') > > > > is equivalent to: > > > > store.category.parent_category.requires = IS_IN_DB(db, db.category.id, > > > > '%(name)s') > > > > since 0 evaluates to False. > > > > > I believe that what you want is: > > > > store.category.parent_category.requires = IS_EMPTY_OR(IS_IN_DB(db, > > > > db.category.id, '%(name)s')) > > > > > Denes. > > > > > On Oct 21, 3:35 am, Calycé wrote: > > > > > > Hi all, > > > > > > I have created a table with a self reference as described below: > > > > > db.define_table('category', > > > > > Field('parent_category', 'reference category'), > > > > > Field('name', 'string', length=40, required=True), > > > > > Field('description', 'text', required=True), > > > > > Field('small_image', 'upload')) > > > > > > Now I'd like to have an "optional requires" clause. For example, if I > > > > > add the following clause "store.category.parent_category.requires = 0 > > > > > or IS_IN_DB(db, db.category.id, '%(name)s')" I have a nice combo > > > > > whenever I use the appdadmin to insert rows BUT I have to select > > > > > something from the combo. In my case, the parent_category field should > > > > > be optional. In extenso, categories without parent_category would be > > > > > root categories so selecting a parent_category is optional. > > > > > > Is there a way to present a combo as does the "requires" but without > > > > > enforcing the field ? Do I have to create a specific form for that ?
[web2py] Re: Is there something like an "optional requires"
That's exactly what I'm experiencing. Do I need to file a bug ? On Oct 21, 4:11 pm, Anthony wrote: > I *think* if you submit a form and immediately reload a new form (as part of > the same action), the new form's dropdown is populated (via the IS_IN_DB > validator) before the db insert of the submitted form, so the new form > doesn't have the most up-to-date set of values. If that's the case, it > should probably be fixed. > > > > > > > > On Friday, October 21, 2011 9:28:38 AM UTC-4, Calycé wrote: > > > Thanks a lot to both of you the IS_EMPTY_OR() was indeed what I was > > needing (note to self: reread the book...) > > > Could anyone of you tell me when the the combo is populated ? I'm just > > asking because now, when I enter a record using the appadmin > > interface, the new record is not appearing in the combo but is > > correctly inserted in the table. I have to reload the page in order to > > see the last inserted category in the combo. > > > For the "0 or" it's a bad cut 'n paste... my bad. > > > On Oct 21, 2:56 pm, DenesL wrote: > > > Hi Calycé, > > > > note that: > > > store.category.parent_category.requires = 0 or IS_IN_DB(db, > > > db.category.id, '%(name)s') > > > is equivalent to: > > > store.category.parent_category.requires = IS_IN_DB(db, db.category.id, > > > '%(name)s') > > > since 0 evaluates to False. > > > > I believe that what you want is: > > > store.category.parent_category.requires = IS_EMPTY_OR(IS_IN_DB(db, > > > db.category.id, '%(name)s')) > > > > Denes. > > > > On Oct 21, 3:35 am, Calycé wrote: > > > > > Hi all, > > > > > I have created a table with a self reference as described below: > > > > db.define_table('category', > > > > Field('parent_category', 'reference category'), > > > > Field('name', 'string', length=40, required=True), > > > > Field('description', 'text', required=True), > > > > Field('small_image', 'upload')) > > > > > Now I'd like to have an "optional requires" clause. For example, if I > > > > add the following clause "store.category.parent_category.requires = 0 > > > > or IS_IN_DB(db, db.category.id, '%(name)s')" I have a nice combo > > > > whenever I use the appdadmin to insert rows BUT I have to select > > > > something from the combo. In my case, the parent_category field should > > > > be optional. In extenso, categories without parent_category would be > > > > root categories so selecting a parent_category is optional. > > > > > Is there a way to present a combo as does the "requires" but without > > > > enforcing the field ? Do I have to create a specific form for that ?
[web2py] Re: Is there something like an "optional requires"
I *think* if you submit a form and immediately reload a new form (as part of the same action), the new form's dropdown is populated (via the IS_IN_DB validator) before the db insert of the submitted form, so the new form doesn't have the most up-to-date set of values. If that's the case, it should probably be fixed. On Friday, October 21, 2011 9:28:38 AM UTC-4, Calycé wrote: > > Thanks a lot to both of you the IS_EMPTY_OR() was indeed what I was > needing (note to self: reread the book...) > > Could anyone of you tell me when the the combo is populated ? I'm just > asking because now, when I enter a record using the appadmin > interface, the new record is not appearing in the combo but is > correctly inserted in the table. I have to reload the page in order to > see the last inserted category in the combo. > > > For the "0 or" it's a bad cut 'n paste... my bad. > > > > On Oct 21, 2:56 pm, DenesL wrote: > > Hi Calycé, > > > > note that: > > store.category.parent_category.requires = 0 or IS_IN_DB(db, > > db.category.id, '%(name)s') > > is equivalent to: > > store.category.parent_category.requires = IS_IN_DB(db, db.category.id, > > '%(name)s') > > since 0 evaluates to False. > > > > I believe that what you want is: > > store.category.parent_category.requires = IS_EMPTY_OR(IS_IN_DB(db, > > db.category.id, '%(name)s')) > > > > Denes. > > > > On Oct 21, 3:35 am, Calycé wrote: > > > > > > > > > > > > > > > > > Hi all, > > > > > I have created a table with a self reference as described below: > > > db.define_table('category', > > > Field('parent_category', 'reference category'), > > > Field('name', 'string', length=40, required=True), > > > Field('description', 'text', required=True), > > > Field('small_image', 'upload')) > > > > > Now I'd like to have an "optional requires" clause. For example, if I > > > add the following clause "store.category.parent_category.requires = 0 > > > or IS_IN_DB(db, db.category.id, '%(name)s')" I have a nice combo > > > whenever I use the appdadmin to insert rows BUT I have to select > > > something from the combo. In my case, the parent_category field should > > > be optional. In extenso, categories without parent_category would be > > > root categories so selecting a parent_category is optional. > > > > > Is there a way to present a combo as does the "requires" but without > > > enforcing the field ? Do I have to create a specific form for that ?
[web2py] Re: Is there something like an "optional requires"
Thanks a lot to both of you the IS_EMPTY_OR() was indeed what I was needing (note to self: reread the book...) Could anyone of you tell me when the the combo is populated ? I'm just asking because now, when I enter a record using the appadmin interface, the new record is not appearing in the combo but is correctly inserted in the table. I have to reload the page in order to see the last inserted category in the combo. For the "0 or" it's a bad cut 'n paste... my bad. On Oct 21, 2:56 pm, DenesL wrote: > Hi Calycé, > > note that: > store.category.parent_category.requires = 0 or IS_IN_DB(db, > db.category.id, '%(name)s') > is equivalent to: > store.category.parent_category.requires = IS_IN_DB(db, db.category.id, > '%(name)s') > since 0 evaluates to False. > > I believe that what you want is: > store.category.parent_category.requires = IS_EMPTY_OR(IS_IN_DB(db, > db.category.id, '%(name)s')) > > Denes. > > On Oct 21, 3:35 am, Calycé wrote: > > > > > > > > > Hi all, > > > I have created a table with a self reference as described below: > > db.define_table('category', > > Field('parent_category', 'reference category'), > > Field('name', 'string', length=40, required=True), > > Field('description', 'text', required=True), > > Field('small_image', 'upload')) > > > Now I'd like to have an "optional requires" clause. For example, if I > > add the following clause "store.category.parent_category.requires = 0 > > or IS_IN_DB(db, db.category.id, '%(name)s')" I have a nice combo > > whenever I use the appdadmin to insert rows BUT I have to select > > something from the combo. In my case, the parent_category field should > > be optional. In extenso, categories without parent_category would be > > root categories so selecting a parent_category is optional. > > > Is there a way to present a combo as does the "requires" but without > > enforcing the field ? Do I have to create a specific form for that ?
[web2py] Re: Is there something like an "optional requires"
Hi Calycé, note that: store.category.parent_category.requires = 0 or IS_IN_DB(db, db.category.id, '%(name)s') is equivalent to: store.category.parent_category.requires = IS_IN_DB(db, db.category.id, '%(name)s') since 0 evaluates to False. I believe that what you want is: store.category.parent_category.requires = IS_EMPTY_OR(IS_IN_DB(db, db.category.id, '%(name)s')) Denes. On Oct 21, 3:35 am, Calycé wrote: > Hi all, > > I have created a table with a self reference as described below: > db.define_table('category', > Field('parent_category', 'reference category'), > Field('name', 'string', length=40, required=True), > Field('description', 'text', required=True), > Field('small_image', 'upload')) > > Now I'd like to have an "optional requires" clause. For example, if I > add the following clause "store.category.parent_category.requires = 0 > or IS_IN_DB(db, db.category.id, '%(name)s')" I have a nice combo > whenever I use the appdadmin to insert rows BUT I have to select > something from the combo. In my case, the parent_category field should > be optional. In extenso, categories without parent_category would be > root categories so selecting a parent_category is optional. > > Is there a way to present a combo as does the "requires" but without > enforcing the field ? Do I have to create a specific form for that ?
[web2py] Re: Is there something like an "optional requires"
IS_EMPTY_OR(IS_IN_DB(...)) See http://web2py.com/book/default/chapter/07#Validators. Anthony On Friday, October 21, 2011 3:35:06 AM UTC-4, Calycé wrote: > > Hi all, > > I have created a table with a self reference as described below: > db.define_table('category', > Field('parent_category', 'reference category'), > Field('name', 'string', length=40, required=True), > Field('description', 'text', required=True), > Field('small_image', 'upload')) > > Now I'd like to have an "optional requires" clause. For example, if I > add the following clause "store.category.parent_category.requires = 0 > or IS_IN_DB(db, db.category.id, '%(name)s')" I have a nice combo > whenever I use the appdadmin to insert rows BUT I have to select > something from the combo. In my case, the parent_category field should > be optional. In extenso, categories without parent_category would be > root categories so selecting a parent_category is optional. > > Is there a way to present a combo as does the "requires" but without > enforcing the field ? Do I have to create a specific form for that ? >