デフォルトのエラー メッセージ ラベルを、ラベルではなく div でオーバーライドしようとしています。私もこの投稿を見て、その方法を理解しましたが、CSS の制限に悩まされています。これらの例のいくつかのようにこれを表示するにはどうすればよいですか:
例 #1 (Dojo) - エラー表示を表示するには無効な入力を入力する必要があります
例 #2
エラー ラベルを div 要素にオーバーライドするコードの例を次に示します。
$(document).ready(function(){
$("#myForm").validate({
rules: {
"elem.1": {
required: true,
digits: true
},
"elem.2": {
required: true
}
},
errorElement: "div"
});
});
今、私はcssの部分で途方に暮れていますが、ここにあります:
div.error {
position:absolute;
margin-top:-21px;
margin-left:150px;
border:2px solid #C0C097;
background-color:#fff;
color:white;
padding:3px;
text-align:left;
z-index:1;
color:#333333;
font:100% arial,helvetica,clean,sans-serif;
font-size:15px;
font-weight:bold;
}
アップデート:
さて、私は今このコードを使用していますが、ポップアップの画像と配置は境界線よりも大きいです.これを動的に調整して高さを変えることはできますか?
if (element.attr('type') == 'radio' || element.attr('type') == 'checkbox') {
element = element.parent();
offset = element.offset();
error.insertBefore(element)
error.addClass('message'); // add a class to the wrapper
error.css('position', 'absolute');
error.css('left', offset.left + element.outerWidth());
error.css('top', offset.top - (element.height() / 2)); // Not working for Radio, displays towards the bottom of the element. also need to test with checkbox
} else {
// Error placement for single elements
offset = element.offset();
error.insertBefore(element)
error.addClass('message'); // add a class to the wrapper
error.css('position', 'absolute');
error.css('left', offset.left + element.outerWidth());
error.css('top', offset.top - (element.height() / 2));
}
CSSは以下と同じです(あなたのCSSコード)
HTML
<span>
<input type="radio" class="checkbox" value="P" id="radio_P" name="radio_group_name"/>
<label for="radio_P">P</label>
<input type="radio" class="checkbox" value="S" id="radio_S" name="radio_group_name"/>
<label for="radio_S">S</label>
</span>