Discussion:
[Erp5-dev] Validation of dialog
Łukasz Nowak
2008-03-05 11:54:22 UTC
Permalink
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.
* 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?

Regards,
Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...'' I am only craftsman.
Jérome Perrin
2008-03-13 20:38:00 UTC
Permalink
Post by Łukasz Nowak
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.
* 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.
Post by Łukasz Nowak
* 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
Łukasz Nowak
2008-03-18 11:23:40 UTC
Permalink
Hello,

On 2008-03-13, 20:38:00
J?rome Perrin <jerome at nexedi.com> wrote:

(...)
Post by Jérome Perrin
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 ).
request.set('portal_status_message', N_('This is not valid !'))
return context.Base_viewYourDialog(request)
Great! For now it is enough. The only thing I miss, is to easy showing
error fields, but I'll try to figure it out.

It was so simple... ;)

Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...'' I am only craftsman.
Loading...