OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.45k stars 2.4k forks source link

OrchardCore.Forms doesn't preserve checked checkbox state when the checkbox doesn't have a default value #17023

Open rjpowers10 opened 1 week ago

rjpowers10 commented 1 week ago

Describe the bug

OrchardCore.Forms will store model state in a cookie so in the event the form is invalid the user can be redirected back to the form with the model state still intact.

Orchard Core version

Main branch as of 05bd65ab262bbee90b63bb23b6f021b7a8c9d820

To Reproduce

  1. Create a new site using the blog recipe.
  2. Enable the OrchardCore.Forms feature.
  3. Add a new form widget to the "content" zone and "always" layer. In the form's flow:
    1. Add the Validation Summary widget.
    2. Add the Input widget.
      1. Name: MyName
      2. ID: MyName
      3. Label option: Standard
      4. Label text: Name
      5. Type: Input
      6. Validation option: Standard
    3. Add the Input widget.
      1. Name: MyCheckbox
      2. ID: MyCheckbox
      3. Label option: Standard
      4. Label text: Click me
      5. Type: Checkbox
      6. Validation option: Standard
    4. Add the Button widget
      1. Name: MyButton
      2. ID: MyButton
      3. Text: Submit
      4. Type: Submit
    5. Add a new workflow like the image below. The idea is to submit the form and force a validation error on the checkbox, then redirect back to the form to display the error.
    6. Copy the action from the Http Request Event and set that as the form action back in the form widget.
    7. Uncheck "validate antiforgery token" from the Http Request Event.

If you get stuck I modified the example "contact" form from the OC docs

image

View the form image

Fill out the form image

Submit the form. The text input state is preserved. The checkbox state is not preserved. image

Expected behavior

Checkbox state is preserved across the redirect (the checkbox remains checked if it was checked when submitted).