嗨,我正在尝试使用 jquery validate 验证一些 jquery 明星。我在这里找到了几个关于这个的答案,但都没有运气。
这是查看源代码中的 HTML,原因是我在轨道上
但它不起作用,我如何验证评级明星,使其成为强制性要求,XD!谢谢..我已经研究了好几天了,请帮助-
正如我所说,我已经尝试过其他问题的答案,但它们对我不起作用
<div id="pasescortos">
<label for="attribute">Short passes</label>
<span class="star-rating-control">
<div class="rating-cancel"><a title="Cancel Rating"></a></div>
<div class="star-rating rater-0 star star-rating-applied star-rating-live" id="player_short_passes_1">
<a title="1">1</a></div><div class="star-rating rater-0 star star-rating-applied star-rating-live" id="player_short_passes_2">
<a title="2">2</a></div><div class="star-rating rater-0 star star-rating-applied star-rating-live" id="player_short_passes_3">
<a title="3">3</a></div><div class="star-rating rater-0 star star-rating-applied star-rating-live" id="player_short_passes_4">
<a title="4">4</a></div><div class="star-rating rater-0 star star-rating-applied star-rating-live" id="player_short_passes_5">
<a title="5">5</a></div></span>
<input class="star star-rating-applied" id="player_short_passes_1" name="player[short_passes]" type="radio" value="1" style="display: none;">
<input class="star star-rating-applied" id="player_short_passes_2" name="player[short_passes]" type="radio" value="2" style="display: none;">
<input class="star star-rating-applied" id="player_short_passes_3" name="player[short_passes]" type="radio" value="3" style="display: none;">
<input class="star star-rating-applied" id="player_short_passes_4" name="player[short_passes]" type="radio" value="4" style="display: none;">
<input class="star star-rating-applied" id="player_short_passes_5" name="player[short_passes]" type="radio" value="5" style="display: none;">
</div>
这里是 JS。
$().ready(function() {
// validate signup form on keyup and submit
$(".edit_player").validate({
ignore:'', // initialize the plugin
errorElement: 'div'});
$("#player_position").rules("add", { required: true, messages: { required: "<%= t('generales.camporequerido') %>"}});
$("#player_short_passes_1").rules("add", { required: true, messages: { required: "<%= t('generales.camporequerido') %>"}});
$("#player_dominant_leg").rules("add", { required: true, messages: { required: "<%= t('generales.camporequerido') %>"}});
});
jQuery.extend(jQuery.validator.messages, {
required: "<%= t('generales.camporequerido') %>",
remote: "Please fix this field.",
email: "Ingresa un correo electrónico válido.",
url: "Please enter a valid URL.",
date: "Please enter a valid date.",
dateISO: "Please enter a valid date (ISO).",
number: "Please enter a valid number.",
digits: "Please enter only digits.",
creditcard: "Please enter a valid credit card number.",
equalTo: "Please enter the same value again.",
accept: "Please enter a value with a valid extension.",
maxlength: jQuery.validator.format("Please enter no more than {0} characters."),
minlength: jQuery.validator.format("Please enter at least {0} characters."),
rangelength: jQuery.validator.format("Please enter a value between {0} and {1} characters long."),
range: jQuery.validator.format("Please enter a value between {0} and {1}."),
max: jQuery.validator.format("Please enter a value less than or equal to {0}."),
min: jQuery.validator.format("Please enter a value greater than or equal to {0}.")
});
编辑1:
我在 HTML 查看源中注意到我的表单有这个 novalidate=""
<form accept-charset="UTF-8" action="/player_steps/skills?locale=en" class="edit_player" id="edit_player_17" method="post" novalidate="novalidate">
奇怪的是我在 Rails 视图中没有 novalidate 标记,它是在 jquery.validate.js 中生成的,对吗?
这就是我在 Rails 中的表单的外观。
<%= form_for @player, :url => wizard_path do |f| %>
在 jquery.rating.js 关于 doble id 问题我发现了这个.. 我该如何解决它?
// insert rating star
var star = $('<div class="star-rating rater-'+ control.serial +'"><a title="' + (this.title || this.value) + '">' + this.value + '</a></div>');
rater.append(star);
// inherit attributes from input element
if(this.id) star.attr('id', this.id);
if(this.className) star.addClass(this.className);