Re: Partial validation results from an invalid input?
Daniel Lepage <[email protected]> Mon, 26 Dec 2011 18:40:16 -0500
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <CANtoCQ9oTy83NELNrV40A1MQbRg2nZAzRe5eQ_PhNq_e74ff6A@mail.gmail.com> |
Hi Chris, This is done through AJAX. I don't have the "enter values, then hit save" workflow - instead, the user can change the values in these form fields at any time and the results are immediately sent to the server and, if valid, saved. The values are used by other parts of the system, so I can't just store the POSTed strings - I need the actual converted values for all the valid POSTed values, even if there are also invalid values. The framework backing this is Flask at a high leve and ToscaWidgets 2 at a lower level, but due to a separate data API the validation is ToscaWidgets-independent. Thanks, Dan On Mon, Dec 26, 2011 at 6:02 PM, Chris Lambacher <[email protected]> wrote: > Hi Dan, > > Use the raw post values to render the page. You shouldn't need > validated values to do so. If you need to get related data using some > of the values, you can check if those values specifically caused > errors and do a more direct conversion if not. > > If you tell me the framework you are using I might be able to provide > you with some more specific tips. > > -Chris > > On Mon, Dec 26, 2011 at 5:55 PM, Daniel Lepage <[email protected]> wrote: >> Hi Chris, >> >> I have a web form that can be edited and saved multiple times. When >> the user inputs data, all valid fields are saved and all invalid >> fields display error messages. >> >> So I need to show the error messages for the invalid fields AND get >> the python values of the valid fields. >> >> Right now my hack is a subclass of Schema that overrides _to_python >> with a function that is char-for-char identical except for a single >> line, where instead of raising Invalid I raise a custom subclass >> (PartialInvalid) that also contains all the valid values. >> >> This works well enough, but it's inelegant, so I was hoping to find a >> better solution. >> >> Thanks, >> Dan >> >> On Mon, Dec 26, 2011 at 5:41 PM, Chris Lambacher <[email protected]> wrote: >>> Hi Dan, >>> >>> There is no official and nice way of doing that and without knowing >>> why you want to do that I would guess "you are doing it wrong". There >>> are some hackish ways that you might be able to get the value but they >>> are likely to be error prone. >>> >>> Can you elaborate on why you want to do it that way? Do you want to >>> display the error? Do you want to ignore the error? >>> >>> -Chris >>> >>> >>> On Mon, Dec 26, 2011 at 5:12 PM, Daniel Lepage <[email protected]> wrote: >>>> Hi everyone, >>>> >>>> Is there a way to get the python values for successful fields in a >>>> Schema when other fields have failed? >>>> >>>> For example, suppose I have the following schema and input value: >>>> >>>> sch = Schema(fields=dict(x=Int(), y=DateConverter(), z=Int())) >>>> v = dict(x='12', y='1/16/1973', z='foo') >>>> >>>> I'd like to validate v against sch in such a way that I get not only >>>> the error message from z, but also the values 12 and datetime(1973, 1, >>>> 16) from x and y, respectively. >>>> >>>> Is there a way to do this? >>>> >>>> None of my use cases rely on chained_validators, so all I need are the >>>> values computed by the fields of the schema. >>>> >>>> Thanks, >>>> Dan Lepage >>>> >>>> ------------------------------------------------------------------------------ >>>> Write once. Port to many. >>>> Get the SDK and tools to simplify cross-platform app development. Create >>>> new or port existing apps to sell to consumers worldwide. Explore the >>>> Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join >>>> http://p.sf.net/sfu/intel-appdev >>>> _______________________________________________ >>>> FormEncode-discuss mailing list >>>> FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org >>>> https://lists.sourceforge.net/lists/listinfo/formencode-discuss >>> >>> >>> >>> -- >>> Christopher Lambacher >>> [email protected] >> >> ------------------------------------------------------------------------------ >> Write once. Port to many. >> Get the SDK and tools to simplify cross-platform app development. Create >> new or port existing apps to sell to consumers worldwide. Explore the >> Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join >> http://p.sf.net/sfu/intel-appdev >> _______________________________________________ >> FormEncode-discuss mailing list >> FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org >> https://lists.sourceforge.net/lists/listinfo/formencode-discuss > > > > -- > Christopher Lambacher > [email protected] ------------------------------------------------------------------------------ Write once. Port to many. Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join http://p.sf.net/sfu/intel-appdev