Created
March 12, 2017 07:51
-
-
Save 1stMinos/1afc272d44b65246fca4a55b96e83bc4 to your computer and use it in GitHub Desktop.
JQuery-Validation-Engine使って、特定条件の時だけ入力させるフォームなどを使うときの話 ref: http://qiita.com/rojiuratech/items/4656908e615835a4c57b
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
<h2>ダンジョンに一人連れて行くとしたら</h2> | |
<input type=“radio” id=sel_0” class="validate[required]" name=“sel” value=“だくねす" >だくねす<br> | |
<input type=“radio” id=sel_1” class="validate[required]" name=“sel” value=“めぐみん” >めぐみん<br> | |
<input type=“radio” id=sel_2” class="validate[required]" name=“sel” value=“ゆんゆん” >ゆんゆん<br> | |
<input type=“radio” id=sel_3” class="validate[required]" name=“sel” value=“そのほか” >そのほか<br> | |
<input type=“text” id=“sel_free” class="condRequired[sel_3]" name=“sel_free” > |
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
<h2>ダンジョンに一人連れて行くとしたら</h2> | |
<input type=“radio” id=sel_0” class="gp validate[required]" name=“sel” value=“だくねす" >だくねす<br> | |
<input type=“radio” id=sel_1” class="gp validate[required]" name=“sel” value=“めぐみん” >めぐみん<br> | |
<input type=“radio” id=sel_2” class="gp validate[required]" name=“sel” value=“ゆんゆん” >ゆんゆん<br> | |
<input type=“radio” id=sel_3” class="gp validate[required]" name=“sel” value=“そのほか” >そのほか<br> | |
<input type=“text” id=“sel_free” class="validate[required]" name=“sel_free” style="display:none;" > |
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
<h2>ダンジョンに一人連れて行くとしたら</h2> | |
<input type=“radio” id=sel_0” name=“sel” value=“だくねす" >だくねす<br> | |
<input type=“radio” id=sel_1” name=“sel” value=“めぐみん” >めぐみん<br> | |
<input type=“radio” id=sel_2” name=“sel” value=“ゆんゆん” >ゆんゆん<br> | |
<input type=“radio” id=sel_3” name=“sel” value=“そのほか” >そのほか<br> | |
<input type=“text” id=“sel_free” name=“sel_free” > | |
<!-- (平仮名4文字なのは見やすくするためだ。悪意はない) --> |
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
//(ブラウザバックを含む)ページが表示されたタイミングで実施する。 | |
window.onpageshow = function(){ | |
jQuery("#form").validationEngine(); | |
appearTextIn(); | |
//ラジオボタン群のどれかがチェックされているかを確認する | |
jQuery(".gp").on("click",function(){ | |
appearTextIn(); | |
}); | |
} | |
//テキスト欄を有効にするか否かの判定実施。複数箇所でよびだされるので関数にした。 | |
var appearTextIn = function(){ | |
var obj = document.getElementById("sel_3"); | |
var isChecked = obj.checked; | |
if ( isChecked == true ){ | |
//「その他」がチェックされていればテキスト入力欄を表示させる | |
document.getElementById("sel_free").style.display = ""; | |
}else{ | |
//上記条件以外なら テキスト入力欄を表示しない | |
document.getElementById("sel_free").style.display = "none"; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment