0

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>

1 Answer 1

1

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;
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I was updating vm.code instead of vm.formData.code in my controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.