Reputation: 63
I have two fields on the form, changing one field value should reset other field value based on conditions. How can i do that.
<select id="code"
name="code"
data-ng-model="vm.formData.code"
data-ng-options="code.id+ ' - ' + code.description for codein vm.codes track by code.id"
data-ng-change="vm.updateTypeField(vm.formData.code, vm.formData.type)"
required>
</select>
<select id="type"
name="type"
data-ng-model="vm.formData.type"
data-ng-options="type.id+ ' - ' + type.description for codein vm.types track by type.id"
data-ng-change="vm.updateCodeField(vm.formData.code, vm.formData.type)"
required>
</select>
Upvotes: 0
Views: 37
Reputation: 810
If i well understood your question, this example may solve the problem. If not, please consider give more details.
Basicaly, updateTypeField()
and updateCodeField()
have access to formData
, so the bellow function would do what you want:
function updateTypeField() {
if (vm.formData.code.id == 2) {
vm.formData.type = undefined;
}
}
Upvotes: 1