Skip to content

Commit e62459a

Browse files
committed
Documentation changes before release
1 parent daa6d42 commit e62459a

File tree

5 files changed

+118
-7
lines changed

5 files changed

+118
-7
lines changed

BREAKING_CHANGES.md

+89-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,94 @@
22

33
This file has all breaking changes across ChameleonForms versions.
44

5-
# Version 4.0.0-beta
5+
# Version 4.0.0-beta0002
6+
7+
## `HTMLAttributes.Attrs` now appends CSS classes rather than replacing them
8+
9+
Previously the following would output `class="second"`, not it will output `class="first second"`:
10+
11+
```cshtml
12+
@(new HtmlAttributes().AddClass("first").Attrs(new Dictionary<string, string>{{"class", "second"}}))
13+
```
14+
15+
### Reason
16+
17+
Allowing CSS classes to be additive was an important need to implement tag helpers.
18+
19+
### Workaround
20+
21+
If you don't want this behaviour you can override the class using `Attr` instead of `Attrs` for the `class` attribute.
22+
23+
24+
## Removed `Partial` and non-async `PartialFor` from `Form` and `Section` and replaced `this.Form()`, `this.FormSection()` and `this.IsInFormSection()` in partial views and removed `this.PartialModelExpression()` from partial views
25+
26+
In order to uplift the partial view capabilities of ChameleonForms and make them easier to use a number of changes have been made:
27+
28+
* All non-async methods of invoking partial views have been removed to [prevent possible deadlocks](https://github.com/aspnet/Mvc/issues/7083)
29+
* Changes have been made as part of introducing tag helpers that means you don't need a special `Partial` method on forms and sections when you are keeping the form model the same; you can now just use the built-in ASP.NET Core partial functionality (i.e. `@Html.PartialAsync` or `<partial>`)
30+
* The ability to determine whether you are in a Form or Section has been expanded to include detection of whether you are within a Field, NAvigation or Message as well and has been implemented so it works anywhere, not just within a partial view. This facilitates tag helper syntax and also allows you to switch between tag helpers and HTML helper syntax if you want
31+
* `PartialModelExpression` is no longer needed with the new functionality
32+
33+
See [the documentation](https://mrcollective.github.io/ChameleonForms/docs/partials.html) for more information.
34+
35+
### Reason
36+
37+
Per above.
38+
39+
### Workaround
40+
41+
* Invoking partial with same model as the parent (use built-in partial functionality)
42+
```cshtml
43+
<partial name="_PartialWithSameModelAsParent" />
44+
45+
@* or *@
46+
47+
@await Html.PartialAsync("_PartialWithSameModelAsParent")
48+
```
49+
50+
* Invoking partial with child property as model, but binding against parent model (use ChameleonForms partial functionality)
51+
```cshtml
52+
<form-partial for="ChildProperty" name="_PartialWithChildModelBindingToParent" />
53+
54+
@* Or, when not in a form section *@
55+
@(await f.PartialForAsync(m => m.ChildProperty, "_PartialWithChildModelBindingToParent"))
56+
57+
@* Or, when in a form section *@
58+
@(await s.PartialForAsync(m => m.ChildProperty, "_PartialWithChildModelBindingToParent"))
59+
```
60+
61+
* Invoking partial with child property as model and binding against that child model (use built-in partial functionality)
62+
```cshtml
63+
<partial name="_PartialWithChildAsModel" model="Model?.ChildProperty" />
64+
65+
@* or *@
66+
67+
@await Html.PartialAsync("_PartialWithChildAsModel", Model?.ChildProperty)
68+
```
69+
70+
* Invoking partial with a different model entirely from the parent (use built-in partial functionality)
71+
```cshtml
72+
<partial name="_PartialWithOtherModel" model="new OtherModel()" />
73+
74+
@* or *@
75+
76+
@await Html.PartialAsync("_PartialWithOtherModel", new OtherModel())
77+
```
78+
79+
* Accessing the current form
80+
```cs
81+
Html.IsInChameleonForm()
82+
Html.GetChameleonForm()
83+
```
84+
85+
* Accessing the current form section
86+
```cs
87+
Html.IsInChameleonFormsSection()
88+
Html.GetChameleonFormsSection()
89+
```
90+
91+
92+
# Version 4.0.0-beta0001
693
794
## .NET Framework no longer supported
895
@@ -14,7 +101,7 @@ ChameleonForms has been upgraded to support ASP.NET Core MVC. It's much easier t
14101
15102
### Workaround
16103
17-
If you want to support .NET Full Framework with MVC 5 then check out v3.0.3 of the [NuGet package](https://www.nuget.org/packages/ChameleonForms/3.0.3) and [documentation](https://chameleonforms.readthedocs.io/en/3.0.3/). If you want to use a different version of .NET Core then [raise an issue](https://github.com/MRCollective/ChameleonForms/issues) to discuss adding that support.
104+
If you want to support .NET Full Framework with MVC 5 then check out v3.0.3 of the [NuGet package](https://www.nuget.org/packages/ChameleonForms/3.0.3) and [documentation](hhttps://chameleonforms.readthedocs.io/). If you want to use a different version of .NET Core then [raise an issue](https://github.com/MRCollective/ChameleonForms/issues) to discuss adding that support.
18105
19106
## DisplayFormatString no longer used
20107

ChameleonForms/ServiceCollectionExtensions.cs

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
namespace ChameleonForms
1515
{
1616
// todo: 4.0 non-beta release
17-
// Doco: antiforgery, HtmlAttrs Dictionary<string, string>, TagHelpers for everything, partials - new syntax, can use them natively, need special one when changing model, Html.GetChameleonFormsSection etc. extensions
18-
// Breaking changes: Removed non-async partial and non `For` partial - can just use partials directly, removed WebViewPage.Form / .FormSection / .IsInFormSection / .PartialModelExpression, merge attributes now adds class
1917
// Build-in DI support e.g. fieldgeneratorrouter
2018
// Review the datetime "g" and current culture things - remove? client side validation for non / separators?
2119
// Update all dependencies to latest versions

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ It's ideally suited for situations where you want to **quickly** build forms tha
3131

3232
### Prerequisites
3333

34-
This library works against netcoreapp3.1. If you are using a different version of .NET Core or are running ASP.NET Core against Full Framework then feel free to [raise an issue](https://github.com/MRCollective/ChameleonForms/issues) to discuss opening up broader support. If you are using ASP.NET MVC 5 then check out v3.0.3 of the [NuGet package](https://www.nuget.org/packages/ChameleonForms/3.0.3) and [documentation](https://chameleonforms.readthedocs.io/en/3.0.3/).
34+
This library works against netcoreapp3.1. If you are using a different version of .NET Core or are running ASP.NET Core against Full Framework then feel free to [raise an issue](https://github.com/MRCollective/ChameleonForms/issues) to discuss opening up broader support. If you are using ASP.NET MVC 5 then check out v3.0.3 of the [NuGet package](https://www.nuget.org/packages/ChameleonForms/3.0.3) and [documentation](https://chameleonforms.readthedocs.io/).
3535

3636
This library works against ASP.NET Core MVC - if you want to use it for Blazor or Razor Pages then feel free to [raise an issue](https://github.com/MRCollective/ChameleonForms/issues) to discuss.
3737

docs/html-attributes.md

+26-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ The `HtmlAttributes` class looks like this and is in the `ChameleonForms` namesp
3333
/// <param name="attributes">A dictionary of attributes</param>
3434
public HtmlAttributes(IDictionary<string, object> attributes);
3535

36+
/// <summary>
37+
/// Constructs a <see cref="HtmlAttributes"/> object using a dictionary to express the attributes.
38+
/// </summary>
39+
/// <example>
40+
/// var h = new HtmlAttributes(new Dictionary&lt;string, string&gt; {{"style", "width: 100%;"}, {"cellpadding", "0"}, {"class", "class1 class2"}, {"src", "http://url/"}, {"data-somedata", "\"rubbi&amp;h\""}});
41+
/// </example>
42+
/// <param name="attributes">A dictionary of attributes</param>
43+
public HtmlAttributes(IDictionary<string, string> attributes);
44+
3645
/// <summary>
3746
/// Constructs a <see cref="HtmlAttributes"/> object using an anonymous object to express the attributes.
3847
/// </summary>
@@ -120,13 +129,27 @@ The `HtmlAttributes` class looks like this and is in the `ChameleonForms` namesp
120129
/// <returns>The <see cref="HtmlAttributes"/> attribute to allow for method chaining</returns>
121130
public HtmlAttributes Attrs(object attributes);
122131

132+
/// <summary>
133+
/// Adds or updates a set of HTML attributes using a dictionary to express the attributes.
134+
/// </summary>
135+
/// <param name="attributes">A dictionary of attributes</param>
136+
/// <returns>The <see cref="HtmlAttributes"/> attribute to allow for method chaining</returns>
137+
public HtmlAttributes Attrs(IDictionary<string, string> attributes);
138+
123139
/// <summary>
124140
/// Implicitly convert from a dictionary to a new <see cref="HtmlAttributes"/> object.
125141
/// </summary>
126142
/// <param name="attributes">The dictionary of HTML attributes</param>
127143
/// <returns>The new <see cref="HtmlAttributes"/> object</returns>
128144
public static implicit operator HtmlAttributes(Dictionary<string, object> attributes);
129145

146+
/// <summary>
147+
/// Implicitly convert from a dictionary to a new <see cref="HtmlAttributes"/> object.
148+
/// </summary>
149+
/// <param name="attributes">The dictionary of HTML attributes</param>
150+
/// <returns>The new <see cref="HtmlAttributes"/> object</returns>
151+
public static implicit operator HtmlAttributes(Dictionary<string, string> attributes);
152+
130153
/// <inheritdoc />
131154
public virtual void WriteTo(TextWriter writer, HtmlEncoder encoder);
132155

@@ -163,7 +186,8 @@ Most `HTMLAttributes` methods map to a tag helper attribute by convention - `Upp
163186
| `Attr(string key, object value)` | `attr-{key}="{value}"` |
164187
| `Attr(Func<object, object> attribute)` | *No equivalent* |
165188
| `Attrs(params Func<object, object>[] attributes)` | *No equivalent* |
166-
| `Attrs(IDictionary<string, object> attributes)` | `attrs="{attributes}"` |
189+
| `Attrs(IDictionary<string, object> attributes)` | *No equivalent* |
190+
| `Attrs(IDictionary<string, string> attributes)` | `attrs="{attributes}"` |
167191
| `Attrs(object attributes)` | *No equivalent* |
168192
| `Disabled(bool disabled = true)` | `disabled="{disabled}"` |
169193
| `Readonly(bool @readonly = true)` | *No equivalent* |
@@ -236,6 +260,7 @@ You can convert a dictionary to a HTML Attributes object, e.g.:
236260

237261
```cs
238262
new Dictionary<string, object>{ {"class", "form"}, {"id", "someForm"} }.ToHtmlAttributes()
263+
new Dictionary<string, string>{ {"class", "form"}, {"id", "someForm"} }.ToHtmlAttributes()
239264
```
240265

241266
## Outputting HTML Attributes

docs/the-form.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The `BeginChameleonForm` extension method looks like this:
9393

9494
***
9595

96-
By default a self-submitting form, against the page model type, that performs a HTTP post with the browser's default `enctype` (usually `application/x-www-form-urlencoded`) is outputted, but you can change the submit location, HTTP verb, `enctype` and add any [HTML attributes you like](html-attributes.md) using the appropriate parameters, e.g.:
96+
By default a self-submitting form, against the page model type, that performs a HTTP post with the browser's default `enctype` (usually `application/x-www-form-urlencoded`) is outputted, but you can change the submit location, HTTP verb, `enctype`, presence of anti forgery token and add any [HTML attributes you like](html-attributes.md) using the appropriate parameters, e.g.:
9797

9898
# [Tag Helpers variant](#tab/configure-form-th)
9999

@@ -162,6 +162,7 @@ If you want to override this behaviour you can configure your own form template.
162162

163163
```html
164164
<form action="%action%" method="%method%" (enctype="%enctype%") (%htmlAttributes%) novalidate="novalidate">
165+
(%antiforgery token%)
165166
```
166167

167168
### End HTML

0 commit comments

Comments
 (0)