Я хочу сделать поле ввода обязательным, если в соответствующем раскрывающемся списке была выбрана опция.Мои 2 поля дублируются после выбора опции из выпадающего списка, чтобы пользователь не ограничивался одной опцией.Итак ... если выбрано exportSupplier
, то agreementReference
становится required
.Однако, если существует более одного exportSupplier
и хотя бы одно из них не выбрано, то форма обрабатывает поля agreementReference
как not required
.
Как создать соответствующее поле agreementReference
required
если был выбран соответствующий exportSupplier
?
vm.exportSuppliers = [{ exportSupplier: '', agreementReference: '' }];
vm.exportSupplierFields = [
{
fieldGroup: [
{
className: 'col-xs-6',
key: 'exportSupplier',
type: 'select2',
templateOptions: {
label: 'Export Supplier',
required: false,
options: [],
onChange: function() {
vm.addExportSupplier();
}
}
},
{
className: 'col-xs-5',
key: 'agreementReference',
type: 'input',
templateOptions: {
label: 'Agreement Reference',
onChange: function() {
vm.addExportSupplier();
}
},
expressionProperties: {
'templateOptions.required': '!!model["exportSupplier"]'
}
}
]
}
];
vm.addExportSupplier = function() {
if (vm.exportSuppliers[vm.exportSuppliers.length - 1].exportSupplier || vm.exportSuppliers[vm.exportSuppliers.length - 1].agreementReference) {
vm.exportSuppliers.push({ exportSupplier: '', agreementReference: '' });
}
};
мой HTML
<div ng-repeat="supplier in vm.exportSuppliers" class="row">
<formly-form model="supplier" fields="vm.exportSupplierFields"
form="vm.informationExportSupplier.form" index="$index">
</formly-form>
</div>
Я пробовал разные варианты, чтобы добавить $ index в это поле 'templateOptions.required', но безуспешно.