Created
September 17, 2014 13:29
-
-
Save tyoshikawa1106/59d67162b487df9b4e6e to your computer and use it in GitHub Desktop.
selectCheckboxesの一括チェック処理サンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="selectCheckboxesCon" id="page"> | |
<apex:form id="form"> | |
<apex:selectCheckboxes value="{!countries}" id="checkBoxes"> | |
<apex:selectOptions value="{!items}"/> | |
</apex:selectCheckboxes><br/> | |
<apex:commandButton value="Apex Check!!" action="{!doApexCheck}" reRender="form" /> | |
<apex:commandButton value="JavaScript Check!!" onclick="return allChecked();" /> | |
</apex:form> | |
<script type="text/javascript"> | |
function allChecked() { | |
// apex:selectOptionsの件数を取得 | |
var itemCnt = '{!items.size}'; | |
console.log(itemCnt); | |
// apex:selectCheckboxesのidを取得 | |
var checkId = '{!$Component.form.checkBoxes}'; | |
console.log(checkId); | |
// リスト件数分チェック処理を実行 | |
for (var i = 0; i < itemCnt; i++) { | |
document.getElementById(checkId + ':' + i).checked = true; | |
} | |
return false; | |
} | |
</script> | |
</apex:page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class selectCheckboxesCon { | |
public List<String> countries {get; set;} | |
public List<SelectOption> items {get; set;} | |
public selectCheckboxesCon() { | |
this.items = getItems(); | |
this.countries = new List<String>(); | |
} | |
public List<SelectOption> getItems() { | |
List<SelectOption> options = new List<SelectOption>(); | |
options.add(new SelectOption('US','US')); | |
options.add(new SelectOption('CANADA','Canada')); | |
options.add(new SelectOption('MEXICO','Mexico')); | |
return options; | |
} | |
/** | |
* ボタンクリック時にチェック | |
*/ | |
public void doApexCheck() { | |
System.debug('Check = ' + this.countries); | |
// selectCheckBoxsの値をセット | |
this.countries = new List<String>(); | |
for (SelectOption o : this.items) { | |
this.countries.add(o.getValue()); | |
} | |
// selectCheckBoxsの値をクリア | |
//this.countries = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment