Skip to content

Commit 38cee79

Browse files
committed
Documentation updates; up to custom-field-generator-handlers.md
1 parent dff0d22 commit 38cee79

18 files changed

+382
-86
lines changed

ChameleonForms.Example/Controllers/ComparisonController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class SignupViewModel
5858
[Required]
5959
public MembershipType MembershipType { get; set; }
6060

61-
[Url]
61+
[DataType(DataType.Url)]
6262
public Uri Homepage { get; set; }
6363
[DataType(DataType.MultilineText)]
6464
public string Bio { get; set; }

ChameleonForms.Example/Controllers/ExampleFormsController.cs

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public ActionResult BasicExample()
2828
return View(new BasicViewModel());
2929
}
3030

31+
[HttpPost]
32+
public ActionResult BasicExample(BasicViewModel vm)
33+
{
34+
return View(vm);
35+
}
36+
3137
public ActionResult Labels()
3238
{
3339
return View(new BasicViewModel());

ChameleonForms.sln

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ EndProject
2727
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{F6A47230-CB64-4380-A326-C5562973F32F}"
2828
ProjectSection(SolutionItems) = preProject
2929
docs\account-signup-render.png = docs\account-signup-render.png
30-
docs\auto-sentence-case.md = docs\auto-sentence-case.md
30+
docs\labels.md = docs\labels.md
3131
docs\boolean.md = docs\boolean.md
3232
docs\bootstrap-buttons.png = docs\bootstrap-buttons.png
3333
docs\bootstrap-example-banner.png = docs\bootstrap-example-banner.png
@@ -41,6 +41,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{F6A47230-C
4141
docs\default-fields.md = docs\default-fields.md
4242
docs\Diagrams.docx = docs\Diagrams.docx
4343
docs\different-form-models.md = docs\different-form-models.md
44+
docs\email.md = docs\email.md
4445
docs\enum.md = docs\enum.md
4546
docs\extending-field-configuration.md = docs\extending-field-configuration.md
4647
docs\extending-form-components.md = docs\extending-form-components.md
@@ -72,6 +73,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{F6A47230-C
7273
docs\the-message.md = docs\the-message.md
7374
docs\the-navigation.md = docs\the-navigation.md
7475
docs\the-section.md = docs\the-section.md
76+
docs\uri.md = docs\uri.md
7577
docs\why.md = docs\why.md
7678
EndProjectSection
7779
EndProject

ChameleonForms/ServiceCollectionExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace ChameleonForms
2424
// * html5 validation off
2525
// * config
2626
// * uri binding
27-
// * update breakingchanges file (displayformatstring -> editformatstring, requiredflagsenum -> required, defaultformtemplate -> SCE)
27+
// * update breakingchanges file (displayformatstring -> editformatstring, requiredflagsenum -> required, defaultformtemplate -> SCE, renamed and moved folders for css/js files)
2828
// * End-to-end documentation review and update - @helper, IHtmlString, web.config, update Message, Navigation etc.
2929
// todo: 4.0 non-beta release
3030
// Review the datetime "g" and current culture things - remove? client side validation for non / separators?

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ This library works against ASP.NET Core MVC - if you want to use it for Blazor o
125125
@section Scripts
126126
{
127127
<partial name="_ValidationScriptsPartial" />
128+
@* ... or relevant equivalent *@
128129
}
129130

130131
```

docs/boolean.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ When using the Default Field Generator then the default HTML of the [Field Eleme
1818
This field will always be Required since it's not nullable.
1919

2020
```html
21-
<input %validationAttrs% %htmlAttributes% id="%propertyName%" name="%propertyName%" type="checkbox" value="true" /> <label for="%propertyName%">%inlineLabel%</label>
21+
<input %validationAttrs% %htmlAttributes% id="%propertyName%" name="%propertyName%" required="required" type="checkbox" value="true" /> <label for="%propertyName%">%inlineLabel%</label>
2222
```
2323

2424
### Nullable Boolean (drop-down with empty option)
@@ -38,7 +38,7 @@ Configurability
3838

3939
### Inline label
4040

41-
If you are outputting a non-nullable Boolean then a label will show next to the field as part of the Field Element. If you want to override just the label text for this label (and not the Field Label as well) then you can do so using the `InlineLabel` method in the Field Configuration, e.g.:
41+
If you are outputting a non-nullable Boolean then a label will show next to the field as part of the Field Element in addition to the Field Label that shows up as part of outputting the full field. If you want to override just the label text for this label (and not the Field Label as well) then you can do so using the `InlineLabel` method in the Field Configuration, e.g.:
4242

4343
```csharp
4444
@s.FieldFor(m => m.BooleanField).InlineLabel("override")
@@ -56,7 +56,7 @@ You can force a Boolean field to display as a drop-down box rather than a checkb
5656
This will change the default HTML for the non-nullable Boolean field as shown above to:
5757

5858
```html
59-
<select %validationAttrs% %htmlAttributes% id="%propertyName%" name="%propertyName%">
59+
<select %validationAttrs% %htmlAttributes% id="%propertyName%" name="%propertyName%" required="required">
6060
<option value="true">Yes</option>
6161
<option value="false">No</option>
6262
</select>
@@ -75,8 +75,8 @@ And it will change the default HTML for the non-nullable Boolean field and the R
7575

7676
```html
7777
<ul>
78-
<li><input %validationAttrs% %htmlAttributes% id="%propertyName%_1" name="%propertyName" type="radio" value="true" /> <label for="%propertyName%_1">%trueDescription%</label></li>
79-
<li><input %htmlAttributes% checked="checked" id="%propertyName%_2" name="%propertyName%" type="radio" value="false" /> <label for="%propertyName%_2">%falseDescription%</label></li>
78+
<li><input %validationAttrs% %htmlAttributes% id="%propertyName%_1" name="%propertyName" required="required" type="radio" value="true" /> <label for="%propertyName%_1">%trueDescription%</label></li>
79+
<li><input %htmlAttributes% checked="checked" id="%propertyName%_2" name="%propertyName%" required="required" type="radio" value="false" /> <label for="%propertyName%_2">%falseDescription%</label></li>
8080
</ul>
8181
```
8282

@@ -92,7 +92,7 @@ And it will change the default HTML for the non-Required nullable Boolean field
9292

9393
### Change the text descriptions of true, false and none
9494

95-
When you display a Boolean field as a drop-down or a list of radio buttons you can change the text that is used to display the `true`, `false` and `none` values to the user. By default the text used is `Yes`, `No` and `None` (except for drop-downs, which have an empty string) respectively. To change the text simply use the `WithTrueAs`, `WithFalseAs` and `WithNoneAs` methods respectively, e.g.:
95+
When you display a Boolean field as a drop-down or a list of radio buttons you can change the text that is used to display the `true`, `false` and `none` values to the user. By default the text used is `Yes`, `No` and `None` (except for drop-downs, which have an empty string instead of `None`) respectively. To change the text simply use the `WithTrueAs`, `WithFalseAs` and `WithNoneAs` methods respectively, e.g.:
9696

9797
```csharp
9898
@s.FieldFor(m => m.NullableBooleanField).WithTrueAs("OK").WithFalseAs("Not OK").WithNoneAs("No comment")
@@ -134,11 +134,11 @@ If you would like to output just a checkbox for a non-nullable boolean field wit
134134
This will change the default HTML for the non-nullable Boolean field as shown above to:
135135

136136
```html
137-
<input %validationAttrs% %htmlAttributes% id="%propertyName%" name="%propertyName%" type="checkbox" value="true" />
137+
<input %validationAttrs% %htmlAttributes% id="%propertyName%" name="%propertyName%" required="required" type="checkbox" value="true" />
138138
```
139139

140140
### Wrap input with label
141-
If you would like to wrap the checkbox with the label you can do so with the `InlineLabelWrapsElement` method in the Field Configuration, e.g.:
141+
If you would like to wrap the checkbox with the inline label you can do so with the `InlineLabelWrapsElement` method in the Field Configuration, e.g.:
142142

143143
```csharp
144144
@s.FieldFor(m => m.BooleanField).InlineLabelWrapsElement()
@@ -147,5 +147,5 @@ If you would like to wrap the checkbox with the label you can do so with the `In
147147
This will change the default HTML for the field as shown above to:
148148

149149
```html
150-
<label><input %validationAttrs% %htmlAttributes% id="%propertyName%" name="%propertyName%" type="checkbox" value="true" /> %inlineLabel%</label>
151-
```
150+
<label><input %validationAttrs% %htmlAttributes% id="%propertyName%" name="%propertyName%" required="required" type="checkbox" value="true" /> %inlineLabel%</label>
151+
```

docs/bootstrap-template.md

+27-41
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,62 @@
11
Twitter Bootstrap 3 Template
22
============================
33

4-
ChameleonForms has a built-in Twitter Bootstrap 3 template that you can switch to with one line of code. This will allow you to rapidly develop forms for your Twitter Bootstrap 3 powered site (which we often use for quick prototyping), but give you the flexibility to easily change the template in the future if your quick prototype makes it big and warrants a custom redesign.
4+
ChameleonForms has a built-in Twitter Bootstrap 3 template that you can switch to as part of [global configuration](configuration.md) or on a [per-form basis](form-template.md). This will allow you to rapidly develop forms for your Twitter Bootstrap 3 powered site (useful for quick prototyping), but give you the flexibility to easily change the template in the future if your quick prototype makes it big and warrants a custom redesign.
5+
6+
Support for Bootstrap 4 and other commonly used templates like Material will be added in the future. If you'd like to add support feel free to issue a [pull request](https://github.com/MRCollective/ChameleonForms/pulls).
57

68
Getting started
79
---------------
810

9-
The easiest way to get up and running with Twitter Bootstrap is to:
10-
11-
1. `Install-Package ChameleonForms.TwitterBootstrap3`
12-
* This includes the `bootstrap` package and the `ChameleonForms` package as dependencies
13-
2. If you already have Twitter Bootstrap referenced in your layout then [add the extra CSS and JavaScript files to your existing bundles](#chameleonforms-custom-css-and-javascript-to-complement-bootstrap) or if you don't then reference the `~/bundles/chameleon-bootstrapjs` JavaScript bundle and `~/bundles/chameleon-bootstrapcss` CSS bundle from your layout or your form pages
14-
3. [Create a ChameleonForm](getting-started#show-me-a-basic-chameleonforms-example-next-to-its-aspnet-mvc-counterpart) using the `BeginChameleonForm` extension method and you are good to go
15-
16-
For more manual steps, to understand the HTML being generated, for instructions for how to modify the template to fit your needs, or to understand what is contained in the `App_Start\TwitterBootstrap.cs` file please see the relevant documentation below.
17-
18-
Make Twitter Bootstrap template the global default
19-
--------------------------------------------------
20-
21-
To easily change the form template for all forms that use the [`BeginChameleonForm` extension method](the-form) simply use this snippet in `Global.asax.cs`:
11+
The easiest way to get up and running with Twitter Bootstrap is to specify it as part of the global config:
2212

23-
```csharp
24-
using ChameleonForms;
25-
using ChameleonForms.Templates.TwitterBootstrap3;
26-
...
27-
FormTemplate.Default = new TwitterBootstrapFormTemplate();
28-
```
13+
1. In `Startup.cs` simply change your `AddChameleonForms` call to reference the `TwitterBootstrap3FormTemplate`:
14+
```cs
15+
public void ConfigureServices(IServiceCollection services)
16+
{
17+
...
18+
services.AddChameleonForms<TwitterBootstrap3FormTemplate>(...);
19+
}
20+
```
2921

30-
Alternatively, you can use one of the other methods of [changing form template](form-templates).
22+
2. If you already have Twitter Bootstrap referenced in your layout then [add the extra CSS and JavaScript files to get validation highlighting looking great](#chameleonforms-custom-css-and-javascript-to-complement-bootstrap)
23+
3. [Create a ChameleonForm](getting-started.md) using the `BeginChameleonForm` extension method and you are good to go
3124

3225
ChameleonForms custom CSS and JavaScript to complement Bootstrap
3326
----------------------------------------------------------------
3427

35-
There are two files that ChameleonForms provides in it's `ChameleonForms.TwitterBootstrap3` package that you can optionally include in your Chameleon-powered Twitter Bootstrap form pages (or your layout if you want to include them across the site):
28+
There are two files that ChameleonForms provides in the [`wwwroot/lib/chameleonforms` folder](configuration.md#msbuild-configuration) that you can optionally include in your Chameleon-powered Twitter Bootstrap form pages (or your layout if you want to include them across the site):
3629

37-
* [chameleonforms-twitterbootstrap.css](https://github.com/MRCollective/ChameleonForms/blob/master/ChameleonForms.Example/Content/chameleonforms-twitterbootstrap.css)
30+
* [chameleonforms-twitterbootstrap.css](https://github.com/MRCollective/ChameleonForms/blob/master/ChameleonForms.Example/wwwroot/lib/chameleonforms/chameleonforms-twitterbootstrap.css)
3831
* Makes form hints a light grey even when the field is invalid (otherwise it would turn red making it look like an error)
3932
* Makes the required designator that ChameleonForms puts in looks better
4033
* Makes field labels for fields that don't have a `<label>` look the same as ones that do (bold) otherwise it looks weird
41-
* [jquery.validate.unobtrusive.twitterbootstrap.js](https://github.com/MRCollective/ChameleonForms/blob/master/ChameleonForms.Example/Scripts/jquery.validate.unobtrusive.twitterbootstrap.js)
34+
* [unobtrusive-twitterbootstrap3-validation.chameleonforms.js](https://github.com/MRCollective/ChameleonForms/blob/master/ChameleonForms.Example/wwwroot/lib/chameleonforms/unobtrusive-twitterbootstrap3-validation.chameleonforms.js)
4235
* Adds the `has-error` class to the field container when there is an unobtrusive validation error
4336
* Removes the `has-error` class from the field container when an invalid field (either from client-side or server-side validation) becomes valid when the user interacts with the field
44-
45-
You can either make use of the bundles we define that group these with the Bootstrap files in our `ChameleonForms.TwitterBootstrap3` NuGet package ([described above](#getting-started)) or add these files to your existing bundles. Note: If you are using the default `~/bundles/jqueryval` that comes with the VC templates then the JavaScript file will already be included with that bundle thanks to the `.Include("~/Scripts/jquery.validate*")`.
37+
* Only supports jQuery validate unobtrusive validation, doesn't yet support [aspnet-validation](https://github.com/ryanelian/aspnet-validation)
4638
4739
HTML Generation
4840
---------------
4941

5042
You can find documentation about the HTML that is generated by the Twitter Bootstrap template across the ChameleonForms documentation:
5143

52-
* [Form HTML](the-form#twitter-bootstrap-3-html)
53-
* [Message HTML](the-message#twitter-bootstrap-3-html) - including the documentation about how the ChameleonForms `MessageType` maps to the Twitter Bootstrap Emphasis Styles
54-
* [Section HTML](the-section#twitter-bootstrap-3-html) - including top-level and nested sections
55-
* [Navigation HTML](the-navigation#twitter-bootstrap-3-html) - including how to add icons to submit buttons, control their size and control their emphasis style (and a [great example of the options](the-navigation#example))
56-
* [Field HTML](field#twitter-bootstrap-3-html) - including:
44+
* [Form HTML](the-form.md#twitter-bootstrap-3-html)
45+
* [Message HTML](the-message.md#twitter-bootstrap-3-html) - including the documentation about how the ChameleonForms `MessageType` maps to the Twitter Bootstrap Emphasis Styles
46+
* [Section HTML](the-section.md#twitter-bootstrap-3-html) - including top-level and nested sections
47+
* [Navigation HTML](the-navigation.md#twitter-bootstrap-3-html) - including how to add icons to submit buttons, control their size and control their emphasis style (and a [great example of the options](the-navigation.md#example))
48+
* [Field HTML](field.md#twitter-bootstrap-3-html) - including:
5749
* The HTML template it uses for inputs, textareas, select boxes, single checkboxes, radio/checkbox lists, file upload controls and other controls
58-
* The default required designator HTML ([which can be overriden]())
59-
* [How to create input groups](field#input-groups) with the `input-group-addon` class automatically added to appended and prepended content
50+
* The default required designator HTML ([which can be overriden](custom-template.md#field))
51+
* [How to create input groups](field.md#input-groups) with the `input-group-addon` class automatically added to appended and prepended content
6052
* The HTML for nested fields
6153

6254
Horizontal and inline forms
6355
---------------------------
6456

65-
The template doesn't currently support [horizontal](http://getbootstrap.com/css/#forms-horizontal) or [inline](http://getbootstrap.com/css/#forms-inline) forms. We will likely create separate templates to achieve that (probably by extending the base on and applying the necessary changes to support these types of forms.
66-
67-
If you create such templates then please send them to us in a [pull request](https://github.com/MRCollective/ChameleonForms/pulls) so we can include them in the main library.
68-
69-
If you are curious to see where this support is in our backlog then please consult our [Trello board](https://trello.com/c/hiwhUxI8/140).
57+
The template doesn't currently support [horizontal](https://getbootstrap.com/docs/3.4/css/#forms-horizontal) or [inline](https://getbootstrap.com/docs/3.4/css/#forms-inline) forms. If you create such templates then please send them to us in a [pull request](https://github.com/MRCollective/ChameleonForms/pulls) so we can include them in the main library.
7058
7159
Modifications
7260
-------------
7361

74-
It's worth noting that the Twitter Bootstrap 3 is a relatively new addition to ChameleonForms at 1.0 (in fact it was the last feature we actively developed in order to meet what we wanted for 1.0). As such we haven't had a chance to use the template in anger so if there is anything that you want to function differently it's entirely possible that it will be useful to other people. Consequently, we encourage you to [raise an issue](https://github.com/MRCollective/ChameleonForms/issues) if you notice something.
75-
76-
If you think that the changes you want to make to the template are specific to your needs then you can [easily extend the template to change the bits you want](custom-template#applying-a-global-template-change) (just extend the `TwitterBootstrapFormTemplate` class), while still using the initial work we have done (and subscribing to updates when you update the ChameleonForms NuGet package).
62+
If you think that the changes you want to make to the template are specific to your needs then you can [easily extend the template to change the bits you want](custom-template#applying-a-global-template-change) (just extend the `TwitterBootstrapFormTemplate` class), while still using the work we have done (and subscribing to updates when you update the ChameleonForms NuGet package).

0 commit comments

Comments
 (0)