我的問題非常簡單。如何將嵌套的formly表單狀態更改爲只讀按鈕
我擁有的東西。
- 我使用從後端接收到的數據(JSON)創建的表單(形式)。
- 表單將是Multilevel Nested(目前它的兩級嵌套)。
- 有一箇中繼器與每個嵌套的表單元素相關聯,只需單擊一個按鈕即可向表單添加另一個元素。
- 頁面頂部會出現一個按鈕,將表單元素的狀態切換爲只讀。我現在面臨
問題 - 當我點擊該按鈕時,表單元素的狀態改變爲只讀的,除了嵌套的那些。
我想
- 當我按一下按鈕,我的形式每一個元素應該改變其狀態爲只讀的,嵌套的或沒有什麼。
這是控制器...後面跟着JS-Bin鏈接。
app.controller('MainCtrl', function MainCtrl(formlyVersion) {
var vm = this;
vm.onSubmit = onSubmit;
vm.exampleTitle = 'Nested Repeating Section';
vm.options = {
formState: {
readOnly: true
}
};
init();
vm.originalFields = angular.copy(vm.fields);
function onSubmit() {
alert(JSON.stringify(vm.model), null, 2);
}
function init() {
vm.fields = [{
key: 'name',
type: 'input',
templateOptions: {
label: 'Name',
required: true,
minlength: 5,
maxlength: 25
}
}, {
key: 'description',
type: 'textarea',
templateOptions: {
label: 'Description',
rows: 5,
maxlength: 100
}
}, {
wrapper: 'panel',
templateOptions: {
label: 'Cars'
},
fieldGroup: [{
type: 'repeatSection',
key: 'cars',
templateOptions: {
btnText: '+',
fields: [{
wrapper: 'panel',
templateOptions: {
label: 'New car'
},
fieldGroup: [{
key: 'carname',
type: 'input',
templateOptions: {
label: 'Name',
required: true,
maxlength: 25
}
}, {
key: 'cardesc',
type: 'input',
templateOptions: {
label: 'Description',
maxlength: 50
}
}]
}]
}
}]
}];
}
});
http://jsbin.com/sunocaf/edit?html,js,output
在此先感謝
附: - 我從官方的有棱角的formly網站上看到了這個例子。
感謝MattE的回答。儘管我沒有用你的方式,因爲我可以在一個月前開始工作。我將發佈我使用的解決方案。再次感謝...乾杯! –