I have been working in the singup form view where I define new fields that are selectors, I need that when you select the first field (Brand), the second shows data depending on the first selector (Brand/Model). To get the data from the database to the selectors I use.
<t t-foreach="request.env['fleet.vehicle.model.brand'].search([])" t-as="brand">
It works perfectly, but the problem is that I need the second selector only shows Models from the brand I selected in the first selector.
How can I get the data from the first selector to use in a search([('brand_id', '=', brand_id)])?
There is on_change in website views?
I paste the code below:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="auth_signup_motomanic.fields"
inherit_id="auth_signup.fields"
name="Auth Signup/ResetPassword form fields">
<xpath expr="//div[@class='form-group field-confirm_password']" position="after">
<div t-attf-class="form-group #{error and 'brand_id' in error and 'has-error' or ''}">
<label class="control-label" for="brand_id">Brand</label>
<select name="brand_id" class="form-control">
<option value="">Brand...</option>
<t t-foreach="request.env['fleet.vehicle.model.brand'].search([])" t-as="brand">
<option t-att-value="brand.id" t-att-selected="brand.id == (int(brand_id) if brand_id else website.user_id.partner_id.vehicle_id.model_id.brand_id.id)">
<t t-esc="brand.name"/>
</option>
</t>
</select>
</div>
<div t-attf-class="form-group #{error and 'model_id' in error and 'has-error' or ''}">
<label class="control-label" for="model_id">Model</label>
<label class="control-label" for="model_id"><t t-esc="brand_id"/></label>
<select name="model_id" class="form-control">
<option value="">Model...</option>
<option value=""><t t-esc="request.params.copy()"/></option>
<t t-foreach="request.env['fleet.vehicle.model'].search([])" t-as="model">
<option t-att-value="model.id" t-att-selected="model.id == (int(model_id) if model_id else website.user_id.partner_id.vehicle_id.model_id.id)">
<t t-esc="model.name"/>
</option>
</t>
</select>
</div>
</data>
</openerp>
You need JS here.