I have a form with four fields:
- Crop - selection
- Active From - date
- Active To - date
- Block Area - selection
How can I make the available options in Block Area depend on the values the user selects for the other fields?
I have a form with four fields:
How can I make the available options in Block Area depend on the values the user selects for the other fields?
To limit the available options based on other field values you can use the
domain
. As an example, this is used on the standard moduleproject_issue
:Quoting the relevant lines:
In this example the
type_id
available options are fetched fromproject.task.type
table, depending on the value of theproject_id
field.I don't know if you can do it with a selection field, but you can change the domain of a many-to-one field when another field changes value. You might also be able to just use the other fields in your BlockArea field's domain, and not have to change it at all. Look at the way the partner address screen sets the domain for the state_id field. You might find this related question helpful.
If you do need to change the domain when another field changes, then the
on_change
event can include adomain
entry in the dictionary it returns.I found a discussion thread that says you can use the selection widget on a many-to-one field, so that might work for you if you set a
domain
for the field. I haven't tried it myself.Try on_change function.. create an on_change function and at the end of the function return the domain condition for the field block_area for example
provide the onchange function on the fields crop, from_date and to_date