The problem is if the field is submitted by the user (even if hidden) it must be validated. If validation fails there must be a way to report the error but there is no visible input field in the form to attach the message to. I think what you have is special enough that should be treated as it is as a special condition. The way you are doing it.
Massimo On Jun 14, 4:40 pm, Hans Donner <hans.don...@pobox.com> wrote: > have an extra state besides readable/writable: submittable (in case of > readable - true) -> field will be processed as hidden (and I assume > validators are run on hidden as well?) > > On Sun, Jun 14, 2009 at 11:35 PM, mdipierro<mdipie...@cs.depaul.edu> wrote: > > > I did learn in this case, that's all I meant. ;-) > > What is your suggestion? > > > Massimo > > > On Jun 14, 4:19 pm, Hans Donner <hans.don...@pobox.com> wrote: > >> Hi Massimo, > > >> it's not about winning - I prefer learning... > > >> On Sun, Jun 14, 2009 at 11:14 PM, mdipierro<mdipie...@cs.depaul.edu> wrote: > > >> > OK. you win. > > >> > On Jun 14, 3:54 pm, Hans Donner <hans.don...@pobox.com> wrote: > >> >> then how to recognise what value was submitted? > > >> >> On 14 jun, 22:53, mdipierro <mdipie...@cs.depaul.edu> wrote: > > >> >> > I would then just handle this manual in onvalidate, no need for the > >> >> > hidden file. > > >> >> > On Jun 14, 5:51 am, Hans Donner <hans.don...@pobox.com> wrote: > > >> >> > > If I have multiple users running the same function, one of the users > >> >> > > should get an error that the year he has been submitting is already > >> >> > > existing and I do not want that what he inserts is the year > >> >> > > following > >> >> > > the one he has been submitting. > >> >> > > (and I'm on GAE, so no uniquess checking there on db level) > > >> >> > > On Sun, Jun 14, 2009 at 12:41 PM, > >> >> > > mdipierro<mdipie...@cs.depaul.edu> wrote: > > >> >> > > > I am pretty sure that if you omit this line: > > >> >> > > > form.append(INPUT(_type='hidden', _value=newyear, _name > >> >> > > > ='newyear')) > > >> >> > > > the field still goes in db because of "default" thus no need for > >> >> > > > validation. > > >> >> > > > Massimo > > >> >> > > > On Jun 14, 2:26 am, Hans Donner <hans.don...@pobox.com> wrote: > >> >> > > >> I think there is, but currently I've came up with: > > >> >> > > >> def year(): > >> >> > > >> # too many - fail > >> >> > > >> if len(request.args) > 1: > >> >> > > >> redirect(URL(r=request,args=[])) > > >> >> > > >> # init > >> >> > > >> table = db.year_year > >> >> > > >> app_settings = AppSettings() > >> >> > > >> arg0 = None > >> >> > > >> if len(request.args) == 1: > >> >> > > >> arg0 = request.args[0] > > >> >> > > >> if arg0 == 'add': > > >> >> > > >> def update_settings(form): > >> >> > > >> requested = form.request_vars.newyear > >> >> > > >> if not app_settings['min_year']: > >> >> > > >> requested = form.vars.year > >> >> > > >> app_settings['min_year'] = requested > >> >> > > >> app_settings['max_year'] = requested > >> >> > > >> app_settings.commit() > > >> >> > > >> def onvalidate_addyear(form): > >> >> > > >> if app_settings['max_year']: > >> >> > > >> next = str(int(app_settings['max_year']) + 1) > >> >> > > >> requested = form.request_vars.newyear > >> >> > > >> if next and requested != next: > >> >> > > >> if requested <= next: > >> >> > > >> session.flash = \ > >> >> > > >> "The year %s has already been added" > >> >> > > >> % requested > >> >> > > >> else: > >> >> > > >> session.flash = \ > >> >> > > >> "The year %s does not follow %s" % > >> >> > > >> (requested, next) > >> >> > > >> redirect(URL(r=request, args=['add'])) > >> >> > > >> form.vars.year = requested > > >> >> > > >> default = dict( > >> >> > > >> table = table, > >> >> > > >> onaccept = update_settings, > >> >> > > >> onvalidation = onvalidate_addyear > >> >> > > >> ) > > >> >> > > >> if app_settings['min_year'] == None: > >> >> > > >> # no years yet - need to add first > >> >> > > >> form = crud.create(**default) > >> >> > > >> return dict(form = form) > >> >> > > >> else: > >> >> > > >> newyear = int(app_settings['max_year']) + 1 > >> >> > > >> table.year.writeable = False > >> >> > > >> table.year.default = newyear > >> >> > > >> form = crud.create(**default) > >> >> > > >> # add field to hold value for input > >> >> > > >> form.append(INPUT(_type='hidden', _value=newyear, > >> >> > > >> _name = > >> >> > > >> 'newyear')) > >> >> > > >> return dict(form = form) > > >> >> > > >> # no add > >> >> > > >> rows = db().select(table.ALL) > >> >> > > >> all_years = extract_field(rows, 'year') > > >> >> > > >> if arg0 and int(arg0) and \ > >> >> > > >> arg0 >= app_settings['min_year'] and arg0 <= > >> >> > > >> app_settings['max_year']: > >> >> > > >> form = crud.read(table, rows[all_years.index(arg0)]) > >> >> > > >> return dict(form = form) > >> >> > > >> elif arg0: > >> >> > > >> redirect(URL(r=request,args=[])) > > >> >> > > >> return dict(app = app_settings.row, years = all_years) > > >> >> > > >> On Sun, Jun 14, 2009 at 2:16 AM, > >> >> > > >> mdipierro<mdipie...@cs.depaul.edu> wrote: > > >> >> > > >> > can you post an example? I am sure there is a better way. > > >> >> > > >> > Massimo > > >> >> > > >> > On Jun 13, 3:28 pm, Hans Donner <hans.don...@pobox.com> wrote: > >> >> > > >> >> the model has some more fields, entered by the user. This > >> >> > > >> >> filed is > >> >> > > >> >> prepopulated by the server. > >> >> > > >> >> On submitting the prepopluated value may be not valid any > >> >> > > >> >> more, but > >> >> > > >> >> may not be updated by the server > >> >> > > >> >> (is considered part of the user submitted fileds). > > >> >> > > >> >> Currently worked around it by adding a hidden field with the > >> >> > > >> >> data and > >> >> > > >> >> supplying an onvalidation. > > >> >> > > >> >> On Sat, Jun 13, 2009 at 6:31 PM, > >> >> > > >> >> mdipierro<mdipie...@cs.depaul.edu> wrote: > > >> >> > > >> >> > I do not understand. If the fields are marked readonly (as > >> >> > > >> >> > in > >> >> > > >> >> > db.table.field.readonly=True) the field is not submitted > >> >> > > >> >> > from the > >> >> > > >> >> > client to the server with the form. The form is populated > >> >> > > >> >> > serverside. > > >> >> > > >> >> > Massimo > > >> >> > > >> >> > On Jun 13, 10:38 am, Hans Donner <hans.don...@pobox.com> > >> >> > > >> >> > wrote: > >> >> > > >> >> >> Well, depends what you call 'inserted by the visitor'. In > >> >> > > >> >> >> this case > >> >> > > >> >> >> I'm prepopulating the form, some fields are not editable, > >> >> > > >> >> >> but the user > >> >> > > >> >> >> should submit these values as well. > >> >> > > >> >> >> Guess I have to use onvalidate then to make sure all is ok. > > >> >> > > >> >> >> The second remark in my original posting: the 'unique' > >> >> > > >> >> >> should somehow > >> >> > > >> >> >> be supported by DAL, or warnings should be submitted that > >> >> > > >> >> >> it is > >> >> > > >> >> >> unsupported. > > >> >> > > >> >> >> On Sat, Jun 13, 2009 at 4:39 PM, > >> >> > > >> >> >> mdipierro<mdipie...@cs.depaul.edu> wrote: > > >> >> > > >> >> >> > back to the original question. Should they validate? If > >> >> > > >> >> >> > they are > >> >> > > >> >> >> > readonly it means they are not inserted by the visitor. > >> >> > > >> >> >> > We only > >> >> > > >> >> >> > validate visitor provided input. > > >> >> > > >> >> >> > Massimo > > >> >> > > >> >> >> > On Jun 13, 9:02 am, Hans Donner <hans.don...@pobox.com> > >> >> > > >> >> >> > wrote: > >> >> > > >> >> >> >> sorry, should be db.table.field.default = '' > > >> >> > > >> >> >> >> On Sat, Jun 13, 2009 at 3:54 PM, > >> >> > > >> >> >> >> mdipierro<mdipie...@cs.depaul.edu> wrote: > > >> >> > > >> >> >> >> > I am not what you mean by: > > >> >> > > >> >> >> >> > db.table.field = 'some invalid value for the > >> >> > > >> >> >> >> > requires[]' > > >> >> > > >> >> >> >> > It seems to be redefining the field. It should give > >> >> > > >> >> >> >> > an error. > > >> >> > > >> >> >> >> > On Jun 13, 8:28 am, Hans Donner > >> >> > > >> >> >> >> > <hans.don...@pobox.com> wrote: > >> >> > > >> >> >> >> >> db.define_table( > >> >> > > >> >> >> >> >> 'test', > >> >> > > >> >> >> >> >> SQLField('unique', 'string', unique = True, > >> >> > > >> >> >> >> >> requires = IS_NOT_IN_DB(db, 'test.unique')), > >> >> > > >> >> >> >> >> ) > > >> >> > > >> >> >> >> >> def pseudo(): > >> >> > > >> >> >> >> >> db.table.field.writable = False > >> >> > > >> >> >> >> >> db.table.field = 'some invalid value for the > >> >> > > >> >> >> >> >> requires[]' > >> >> > > >> >> >> >> >> form = crud.create(db.table) > > >> >> > > >> >> >> >> >> the form doesn't run the validators for the > >> >> > > >> >> >> >> >> non-writable field, and > >> >> > > >> >> >> >> >> when you are on GAE the uniqueness is not enforced > >> >> > > >> >> >> >> >> on db level (and > >> >> > > >> >> >> >> >> DAL does not make up for this). > > >> >> > > >> >> >> >> >> When I have the following: > >> >> > > >> >> >> >> >> def pseudo(): > >> >> > > >> >> >> >> >> db.table.field = 'some invalid value for the > >> >> > > >> >> >> >> >> requires[]' > >> >> > > >> >> >> >> >> form = crud.create(db.table) > >> >> > > >> >> >> >> >> form.custom.widget.jaar.update(**dict(_disabled = > >> >> > > >> >> >> >> >> True)) > > >> >> > > >> >> >> >> >> the value is non-editable by the user, it is > >> >> > > >> >> >> >> >> validated but the value is removed --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---