Discussion:
[Erp5-dev] dynamic form fields - how to do?
Jacek Medrzycki
2007-03-09 10:56:14 UTC
Permalink
Hi

I have the following problem:

There is a field in the form, say "Recruitment type", which is a
listfield with 2 values:
External
Internal
(this is associated with recruitment_type property)

Then, I have RelationStringField (for referral relation) that should,
when clicked on the gear wheel:
a) In Internal recruitment type, display a list of Persons,
b) In External recruitment type, display a list of Announcements.

It is easy to write a TALES expression in "Portal Type" field, that
makes relation string field display only Persons or Announcements,
according to recruitment_type. It works good after initial load of the form.

But then, user can change the value on a Recruitment Type list field. In
such a case, relation string, when clicked on gear wheel, would display
wrong portal type.
I've attached javascript method to the list field:
onchange='form.submit()', so the form is reloaded when user changes
value in list field.
But then I've found out that my TALES expression is not re-evaluated
after form is reloaded, so the releation string field is still
associated with wrong portal type.

The question is - what should I do to make TALES re-evaluate after form
is reloaded? Definitely there is such a way, 'couse TALESes are
evaluated after user click gear wheel and then click "Update relation".
I need similar behaviour for list field.

Regards,
Jacek
Jérôme Perrin
2007-03-12 08:38:08 UTC
Permalink
Post by Jacek Medrzycki
Hi
There is a field in the form, say "Recruitment type", which is a
External
Internal
(this is associated with recruitment_type property)
Then, I have RelationStringField (for referral relation) that should,
a) In Internal recruitment type, display a list of Persons,
b) In External recruitment type, display a list of Announcements.
It is easy to write a TALES expression in "Portal Type" field, that
makes relation string field display only Persons or Announcements,
according to recruitment_type. It works good after initial load of the form.
But then, user can change the value on a Recruitment Type list field. In
such a case, relation string, when clicked on gear wheel, would display
wrong portal type.
onchange='form.submit()', so the form is reloaded when user changes
value in list field.
This will be a very strange behaviour for the user. Only clicking on save
button (or pressing enter) should save data.
Post by Jacek Medrzycki
But then I've found out that my TALES expression is not re-evaluated
after form is reloaded, so the releation string field is still
associated with wrong portal type.
This is just because the TALES is evaluated on the current version of the
object, but the object is not modified yet.
Post by Jacek Medrzycki
The question is - what should I do to make TALES re-evaluate after form
is reloaded? Definitely there is such a way, 'couse TALESes are
evaluated after user click gear wheel and then click "Update relation".
I need similar behaviour for list field.
You could make it work by looking the value in REQUEST, but I would suggest a
different approach, because even if you can restrict the portal type of
referal relation based on recruitment_type property, the user can later
change recruitement_type and your data is inconsistant. Trying to keep data
consistent at the form level (eg. using required field or TALES) is not
always possible.

In your case, you should allow the user to set a referer to both an
Anouncement or a Person, and check the consistency by raising a
ValidationFailed when the user pass a workflow transition (eg.
validate_action).

You could also make different portal types (Internal Recruitement and External
Recruitement) that use different forms.

J?rome
Jacek Medrzycki
2007-03-12 17:08:18 UTC
Permalink
Post by Jérôme Perrin
In your case, you should allow the user to set a referer to both an
Anouncement or a Person, and check the consistency by raising a
ValidationFailed when the user pass a workflow transition (eg.
validate_action).
We did it exactly that way, but the client doesn't like that. He wants
to see only Annoucements or Persons, according to recruitment type.

J.

Loading...