JQuery 1.5 और बाद में 1.5.1 में अपग्रेड करने के बाद, मेरी तुलना सत्यापन विफल हो जाता है। मैं JQuery.Validate 1.7 का उपयोग कर रहा हूँ। माई व्यू मॉडेल में निम्नलिखित डेटा एनोटेशन हैं:JQuery 1.5 ब्रेक Validate की तुलना करें (JQuery मान्य 1.8)
/// <summary>
/// Gets or sets the full name.
/// </summary>
/// <value>The full name.</value>
[Required]
[Display(Name = "fullname", ResourceType = typeof(Milkshake.Commerce.Model.Resources.Text))]
public string FullName { get; set; }
/// <summary>
/// Gets or sets the email.
/// </summary>
/// <value>The email.</value>
[DataType(DataType.EmailAddress)]
[Display(Name = "email", ResourceType = typeof(Milkshake.Commerce.Model.Resources.Text))]
[Required(ErrorMessageResourceName = "EmailRequired", ErrorMessageResourceType = typeof(Milkshake.Commerce.Model.Resources.ValidationMessages))]
[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessageResourceType = typeof(Milkshake.Commerce.Model.Resources.ValidationMessages), ErrorMessageResourceName = "EmailInvalid")]
public string Email { get; set; }
/// <summary>
/// Gets or sets the password.
/// </summary>
/// <value>The password.</value>
[DataType(DataType.Password)]
[Display(Name = "password", ResourceType = typeof(Milkshake.Commerce.Model.Resources.Text))]
[Required(ErrorMessageResourceName = "PasswordRequired", ErrorMessageResourceType = typeof(Milkshake.Commerce.Model.Resources.ValidationMessages))]
[ValidatePasswordLengthAttribute(ErrorMessageResourceName = "PasswordLength", ErrorMessageResourceType = typeof(Milkshake.Commerce.Model.Resources.ValidationMessages))]
public string Password { get; set; }
/// <summary>
/// Gets or sets the confirm password.
/// </summary>
/// <value>The confirm password.</value>
[DataType(DataType.Password)]
[Display(Name = "confirmPassword", ResourceType = typeof(Milkshake.Commerce.Model.Resources.Text))]
[Required(ErrorMessageResourceName = "PasswordRequired", ErrorMessageResourceType = typeof(Milkshake.Commerce.Model.Resources.ValidationMessages))]
[Compare("Password", ErrorMessageResourceName = "PasswordsMustMatch", ErrorMessageResourceType = typeof(Milkshake.Commerce.Model.Resources.ValidationMessages))]
public string ConfirmPassword { get; set; }
मैं जो भी मूल्य दर्ज करता हूं, पासवर्ड फ़ील्ड कभी समान नहीं होते हैं।
अद्यतन - एएसपी.नेट एंटीफोर्गेरी टोकन परेशानी में पड़ता है।
FireBug breakpoints की स्थापना में चारों ओर बेवकूफ बनाना के बाद, मैंने देखा है कि equalTo मान्यता समारोह में, jquery.validate.js में लाइन 1065 से शुरू होने वाले, लक्ष्य तत्व है कि पाया जाता है, नहीं पासवर्ड क्षेत्र है - लेकिन __RequestVerificationToken
कि जब आप Html.AntiForgeryToken()
सहायक का उपयोग करते हैं तो एएसपी.नेट एमवीसी लिखता है।
तो इसका मतलब है कि हम सही इनपुट तत्वों की तुलना भी नहीं कर रहे हैं। इस समस्या के समाधान के लिए, मैं jquery.validate.js फाइल करने के लिए एक गंदा हैक कहा:
// http://docs.jquery.com/Plugins/Validation/Methods/equalTo
equalTo: function (value, element, param) {
// bind to the blur event of the target in order to revalidate whenever the target field is updated
// TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
var target = $(param).unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
$(element).valid();
});
if ($(target).is("input[type=hidden]") && $(target).attr("name") == "__RequestVerificationToken") {
var otherElementId = $(element).attr("id");
var underScoreIndex = otherElementId.indexOf("_");
otherElementId = otherElementId.substring(0, underScoreIndex + 1);
otherElementId += $(element).attr("data-val-equalto-other").substring(2);
target = $("#" + otherElementId);
}
return value == target.val();
}
इस हैक, डेटा-वैल-equalto-अन्य विशेषता के मूल्य लेता है, और अपने स्वयं के आईडी के साथ यह मिश्रण, सही इनपुट तत्व खोजने के लिए। सभी मामलों में काम नहीं करेगा। लेकिन उपरोक्त मामले में, मेरे लिए काम करता है।
यह काम करता है! आश्चर्य है कि अगर यह बग माइक्रोसॉफ्ट ब्रह्मांड में कहीं दायर किया गया है। अगली रिलीज में इसे ठीक करने के लिए मुझे माइक्रोसॉफ्ट कनेक्ट के जरिए इसकी रिपोर्ट करनी चाहिए। – MartinHN
यह कोड में तय किया गया है। धन्यवाद। http://connect.microsoft.com/VisualStudio/feedback/details/665793/jquery-unobtrusive-validate-equalto-fails-with-compare-attribute – jsgoupil
यह बहुत उपयोगी था! हालांकि, मेरे मामले में मुझे इसे तत्व = $ (options.form) में बदलना पड़ा। ढूँढें (": इनपुट [name = '" + fullOtherName.replace ("।", "\\।") + "']") [0]; इंजेक्शन मूल्य के चारों ओर एकल उद्धरण नोट करें। और इसे मिनी संस्करण में ठीक करने के लिए मत भूलना! :) –