/ /選択したチェックボックスを5の数に制限します-extjs、extjs4

選択したチェックボックスを5 - extjs、extjs4の数に制限する

6つのチェックボックスがあり、デフォルトでは2つのチェックボックスがありますロード時に、さらにチェックボックスを選択したいのですが、すべてのチェックボックスを選択しようとすると、アラートが表示され、すべてを選択することはできません。すべての条件で、1つまたは最大5つのチェックボックスを選択できることを意味します。では、どうすればこれを実装できますか?

回答:

回答№1は1

チェックボックスグループを使用して、変更時に検証します。これが実際の例です:

{
xtype: "checkboxgroup",
fieldLabel: "Two Columns",
// Arrange checkboxes into two columns, distributed vertically
columns: 2,
vertical: true,
msgTarget: "title",
listeners: {
change: function(cb,nv,ov) {
if(Ext.isArray(nv.rb)) {
if(nv.rb.length > 5){
cb.markInvalid("You can select only 5!");
} else {
cb.clearInvalid();
}
} else {
cb.markInvalid("You need to select at least 2!");
}
}
},
items: [
{ boxLabel: "Item 1", name: "rb", inputValue: "1", checked: true },
{ boxLabel: "Item 2", name: "rb", inputValue: "2", checked: true },
{ boxLabel: "Item 3", name: "rb", inputValue: "3" },
{ boxLabel: "Item 4", name: "rb", inputValue: "4" },
{ boxLabel: "Item 5", name: "rb", inputValue: "5" },
{ boxLabel: "Item 6", name: "rb", inputValue: "6" }
]
}