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?
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 a domain
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.
To limit the available options based on other field values you can use the domain
. As an example, this is used on the standard module project_issue
:
Quoting the relevant lines:
class project_issue(crm.crm_case, osv.osv):
_columns = {
'project_id':fields.many2one('project.project', 'Project'),
'type_id': fields.many2one ('project.task.type', 'Stages', domain="[('project_ids', '=', project_id)]"),
}
In this example the type_id
available options are fetched from project.task.type
table, depending on the value of the project_id
field.
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
def onchange_for_block_area(self,cr,uid,ids,crop,from_date,to_date,context):
domain=[]
#
#some statements for finding the domain
#
return {'domain':{'block_area': domain}}
provide the onchange function on the fields crop, from_date and to_date