jquery-validation-unobtrusive
jquery-validation-unobtrusive copied to clipboard
AddSingleVal doesn't work when attribute is unspecified.
(Sorry for the brevity, posting from phone as work proxies no block HTTP POST to github "to prevent uploads" ffs)
In the line starting "setValidationRules(", attribute is used verbatim, whilst it it coalesced with "val" in the previous line. This means options.params can be {"val":"10"} but it tries to use undefined as the key.
@kichalla, can you please look into this when you'll be back? Thanks!
Yes, this is a bug.
Just ran into this as well.
Both the code, and the comments, indicate that if you leave off the attribute parameter, it will default to "val". However it's not done in both places it's needed to behave this way. Until it's fixed, it's actually a required field in order to get the expected behavior, and "val" (or whatever name you plan on using) should be passed as the attribute parameter.
Fix would take mere seconds by changing https://github.com/aspnet/jquery-validation-unobtrusive/blob/74e6ccc7933ac224bdbef84b8dfff6d7ec19f286/src/jquery.validate.unobtrusive.js#L331-L333 to
return this.add(adapterName, [attribute || "val"], function (options) {
setValidationValues(options, ruleName || adapterName, options.params[attribute || "val"]);
});
Closing this issue in favor of https://github.com/dotnet/aspnetcore/issues/8573
Ideally I'd really like to see this get fixed instead of closing it and sweeping it under the rug. The unobtrusive validation library is still the default script included in new ASP.NET Core projects, even if I create a brand new one today using .NET 6.0, and has been the default in new ASP.NET projects for a long time. Given how small the correction would be (or any other bug fixes that might be needed), even if the plan is to eventually retire it, this is still supported for the time being is it not? Is this not included in the ASP.NET support/release lifecycle?
Also the issue you mention looks to just be a discussion item? Is the validation in Bootstrap 5 the new default for the upcoming ASP.NET Core 7? Is the unobtrusive validation library no longer being included in new 7.0 projects?