Skip to content

FormHelper 6.0 - #44

Merged
sinanbozkus merged 8 commits into
masterfrom
v6
Sep 24, 2026
Merged

sinanbozkus merged 8 commits into
masterfrom
v6

Conversation

@sinanbozkus

Copy link
Copy Markdown
Owner

FormHelper 6.0 is a major release. The upgrade steps are in MIGRATION.md, which also has a prompt for AI assistants.

What's new

  • .NET Core 3.1 to .NET 10. The FormHelper package has no dependencies.
  • No jQuery needed. formhelper.js is plain JavaScript. It uses jQuery Validation Unobtrusive when the page has it, otherwise a built-in validator that reads the same data-val-* attributes (including [Remote]). formhelper.bundle.js includes jQuery Validation and Unobtrusive for jQuery projects (jQuery 3 and 4).
  • Razor Pages: put [FormValidator] on the PageModel.
  • FormHelper.FluentValidation, a new package that replaces the deprecated FluentValidation.AspNetCore integration. It validates [FormValidator] actions and pages asynchronously (MustAsync works) and adds client-side rules. Works with FluentValidation 11 and 12.
  • FormResult is an IActionResult with its own camelCase JSON. It is independent of the application's JSON settings.
  • RedirectToAction, RedirectToPage, Redirect and LocalRedirect work from FormHelper posts. TempData is kept.
  • New options: messages (ErrorMessage, InvalidRequestMessage), localization, CSS classes for Bootstrap/Tailwind, client validation engine.
  • A JavaScript API (FormHelper.submit/validate/reset/fill/showErrors/configure), DOM events, custom validation rules.
  • <formhelper-scripts /> and <formhelper-styles /> tag helpers with versioned urls.
  • Server messages (including [Remote] responses) are always shown as text.

Breaking changes

See MIGRATION.md. In short:

  • Create...Result methods return FormResult instead of JsonResult.
  • validationErrors[i].message is now messages (an array).
  • beforeSubmit gets (form, request).
  • fillFormFields / fhReset are replaced by FormHelper.fill / FormHelper.reset.
  • The EmbeddedFiles option and the dist folder were removed.

Tests

  • xUnit tests on .NET Core 3.1, 6, 8 and 10, with FluentValidation 11 and 12. On the older runtimes they also run against the real FluentValidation.AspNetCore package.
  • Browser tests of the client script against the sample in headless Chrome (cd client && npm test), with and without jQuery.
  • CI runs all of them. The .NET Core 3.1 tests run on Windows, because current Linux images lack OpenSSL 1.1.

Closes #12, closes #22, closes #25, closes #35, closes #37, closes #38, closes #41.

- Target .NET Core 3.1 and .NET 5 to 10; no package dependencies
  (Newtonsoft.Json, Razor runtime compilation and embedded file provider removed)
- FormResult is an IActionResult that writes its own camelCase JSON;
  validation errors carry a list of messages; CreateValidationErrorResult
- [FormValidator] works on Razor Pages, runs IFormModelValidator (async),
  skips GET requests, returns a FormResult for an invalid antiforgery token
- Redirect results (RedirectToAction, RedirectToPage...) become a FormResult
  redirect, keeping TempData; method-preserving redirects are left as they are
- An invalid token rejected before [FormValidator] (Razor Pages,
  [AutoValidateAntiforgeryToken]) also returns FormHelper's message
- <formhelper-scripts /> and <formhelper-styles /> with versioned urls
- New options: InvalidRequestMessage, ErrorMessage, ClientValidation,
  InputErrorCssClass, MessageErrorCssClass, LocalizationResourceType,
  JsonSerializerOptions
- Forms get data-formhelper / data-fh-* attributes
- Removed: EmbeddedFiles option, FormConfig.FormTitle, the dist folder
- Plain JavaScript in client/src, built with esbuild into
  src/FormHelper/Scripts and src/FormHelper/Styles (npm run build / check)
- Works with or without jQuery: jQuery Validation Unobtrusive when it is on
  the page, otherwise a built-in validator reading the same data-val-* rules,
  including [Remote] and custom rules (FormHelper.validation.addRule)
- formhelper.bundle.js includes jQuery Validation 1.22.1 and Unobtrusive 4.0.0,
  skipped when the page already has them; jQuery 3 and 4
- Server messages are shown as text ([Remote] responses too)
- JavaScript API (submit, validate, reset, fill, showErrors, configure),
  DOM events and beforeSubmit(form, request) / callback(result, form)
- fhToastr without jQuery; messages escaped by default
- Removed: $.fn.fillFormFields, $.fn.fhReset, fhToastr.information
A replacement for the deprecated FluentValidation.AspNetCore integration,
for FluentValidation 11 and 12:

- AddFormHelperFluentValidation() validates the models of [FormValidator]
  actions and Razor Pages asynchronously (MustAsync works)
- Client-side attributes for NotNull, NotEmpty, Length, MinimumLength,
  MaximumLength, Matches, EmailAddress, CreditCard, InclusiveBetween,
  GreaterThanOrEqualTo / LessThanOrEqualTo a constant and Equal to another
  property; rules with conditions or that the browser can't run the same way
  (e.g. regex with RegexOptions, \w \d \b, .NET-only syntax) stay on the server
- Steps aside when FluentValidation.AspNetCore's auto validation or client
  adapters are registered, so nothing is validated twice
- FormHelper.Tests and FormHelper.FluentValidation.Tests (xUnit) on
  .NET Core 3.1, .NET 6, 8 and 10; FluentValidation 11 and 12, and the real
  FluentValidation.AspNetCore package on the older runtimes
- Browser tests of the client script against the sample in headless Chrome
  (cd client && npm test), with and without jQuery
.NET 10 and Bootstrap 5; pages with jQuery (tag helper, html helper),
without jQuery (JSON data type), Razor Pages, normal posts and a form loaded
into a modal. Uses FormHelper.FluentValidation.
- README rewritten for 6.0, MIGRATION.md with a prompt for AI assistants
- CI: .NET tests on .NET Core 3.1 (Windows), 6, 8 and 10, client build check,
  browser tests and packages
- Release workflow attaching the scripts and styles to GitHub releases
The Title field also has a [Remote] rule. On a slower machine (CI) the
server didn't answer within the fixed wait, so the rule under test hadn't
run yet.
- Exclude the built scripts/styles and the vendored jQuery Validation files
  from the analysis (.sonarcloud.properties)
- CI installs npm packages without lifecycle scripts
- Tests get free ports from the OS instead of random numbers
- Subresource integrity for the sample's CDN files
- Timeouts for the FluentValidation adapter's regular expressions
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant