Re: [FE-discuss] RequireIfPresent

Top Page
Author: tpc247
Date:  
To: Ian Bicking
CC: formencode-discuss
Subject: Re: [FE-discuss] RequireIfPresent
On 5/13/08, Ian Bicking <ianb@???> wrote:
>
>
> Schemas require the fields to be present unless you put if_missing=None in
> the validator. In this case you need:
>
> phone_type_pri = validators.PlainText(if_missing=None)
>
> I also added an explanation to the RequireIfPresent docstring.




hey Ian, thanks for taking the time to respond. When I did what you
suggested, and tested it out with no input for Primary Phone, I no longer
saw the "phone_type_pri: Missing value" error message. However, when I
typed in a phone number, but did not choose a phone type, e.g., Home Phone,
Office Phone, Cell Phone, etc, then it seems I am no longer prompted to
enter in a phone type, as one would expect:

class Appl_Form(formencode.Schema):
    email = validators.Email(resolve_domain=True, not_empty=True)
    confirm_email = validators.Email(not_empty=True)
    primary_phone = validators.PhoneNumber()
    phone_type_pri = validators.PlainText(if_missing=None)
    #phone_type_pri = validators.PlainText(if_missing=True)
    chained_validators = [validators.FieldsMatch('email', 'confirm_email'),
validators.RequireIfPresent('phone_type_pri', present='primary_phone')]

I'm not sure why you recommend I set if_missing to 'None' instead of
'True'. By the way, I've used if_missing=True before, as a way of
indicating that a particular field in an application form may not even show
up on an application form, depending on user input to questions presented
before the application form is generated. What you're saying doesn't seem
to make sense. I want the 'Primary Phone' and 'Phone Type' fields presented
to all users. A phone number from the user is optional, but as soon as s/he
types one in, then 'Phone Type' should be required. Maybe there is
something I'm missing...
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/_______________________________________________
FormEncode-discuss mailing list
FormEncode-discuss@???
https://lists.sourceforge.net/lists/listinfo/formencode-discuss