[Erp5-dev] Validation of dialog

Jérome Perrin jerome at nexedi.com
Thu Mar 13 21:38:00 CET 2008


Łukasz Nowak a écrit :
> Hello,
> 
> I'm showing user quite complicated dialog (which functionality is quite
> similar to PackingList_viewSolveActionsDialog) and I have to validate
> it much - as after it's invocation, many actions are taken.
> 
> For now I'm validating every field of it - some are required, some not.
> But in my situation there is dependency - if field A is not empty,
> than, and only then field B is required. Well - I've attached script as
> external validator to field B, which checks field A state (given in
> request.get('field_a') ), and validates field B.
> 
> And I'm able to use such solution for all fields, which are dependant,
> but it is quite ugly.
> 
> So my questions:
>  * is there any nice way to validate form as a whole? I wasn't able to
> find such way in form's management tabs.

no, it should be done in the called script.

>  * if no, I was thinking about doing post-validation in called script,
> then return to form with nice message - but then my form "forgets"
> values. I was suggested to pass everything what shall be remembered
> in request, that use TALES to reshow form, but maybe someone has better
> solution?

In Base_edit, when the form does not validate, the form is called again 
in the same REQUEST, and fields display old values because they lookup 
the value in the REQUEST ( this is done in _get_default method in 
Products/Formulator/Field.py ).

It's possible to do something similar in the dialog's action script:

if invalid:
   request.set('portal_status_message', N_('This is not valid !'))
   return context.Base_viewYourDialog(request)

Jérome






More information about the Erp5-dev mailing list