jquery-validation-unobtrusive icon indicating copy to clipboard operation
jquery-validation-unobtrusive copied to clipboard

AddSingleVal doesn't work when attribute is unspecified.

Open Emyr42 opened this issue 8 years ago • 3 comments

(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.

Emyr42 avatar May 09 '17 09:05 Emyr42

@kichalla, can you please look into this when you'll be back? Thanks!

mkArtakMSFT avatar Feb 12 '18 22:02 mkArtakMSFT

Yes, this is a bug.

kichalla avatar May 21 '18 16:05 kichalla

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"]);
        });

nickalbrecht avatar Nov 29 '18 02:11 nickalbrecht

Closing this issue in favor of https://github.com/dotnet/aspnetcore/issues/8573

javiercn avatar Oct 19 '22 14:10 javiercn

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?

nickalbrecht avatar Oct 29 '22 03:10 nickalbrecht