|
4 | 4 |
|
5 | 5 | <h2>Create</h2>
|
6 | 6 |
|
7 |
| -<form> |
8 |
| - @Html.AntiForgeryToken() |
9 |
| - |
| 7 | +@* anti-forgery is on by default *@ |
| 8 | +@* form will special-case anything that looks like a URI i.e. contains a '/' or doesn't match an action *@ |
| 9 | +<form anti-forgery="false" action="Create"> |
10 | 10 | <div class="form-horizontal">
|
11 |
| - <validation-summary tag="div"/> |
| 11 | + @* validation summary tag helper will target just <div/> elements and append the list of errors *@ |
| 12 | + @* - i.e. this helper, like <select/> helper has ContentBehavior.Append *@ |
| 13 | + @* validation-model-errors-only="true" implies validation-summary="true" *@ |
| 14 | + @* helper does nothing if model is valid and (client-side validation is disabled or validation-model-errors-only="true") *@ |
| 15 | + @* don't need a bound attribute to match Html.ValidationSummary()'s headerTag parameter; users wrap message as they wish *@ |
| 16 | + @* initially at least, will not remove the <div/> if list isn't generated *@ |
| 17 | + @* - should helper remove the <div/> if list isn't generated? *@ |
| 18 | + @* - (Html.ValidationSummary returns empty string despite non-empty message parameter) *@ |
| 19 | + <div validation-summary="true" validation-model-errors-only="true"> |
| 20 | + <span style="color:red">This is my message</span> |
| 21 | + </div> |
12 | 22 |
|
13 |
| - @* element will have correct name and id attributes for Id property. but will submit a constant value. *@ |
| 23 | + @* element will have correct name and id attributes for Id property. unusual part is the constant value. *@ |
| 24 | + @* - the helper will _not_ override the user-specified "value" attribute *@ |
14 | 25 | <input type="hidden" for="Id" value="0" />
|
15 | 26 |
|
16 | 27 | <div class="form-group">
|
17 |
| - <label for="Name" class="control-label col-md-2" /> |
| 28 | + @* no special-case for the "for" attribute; may eventually need to opt out on per-element basis here and in <form/> *@ |
| 29 | + <label for="Name" class="control-label col-md-2" style="color:blue" /> |
18 | 30 | <div class="col-md-10">
|
19 |
| - <input type="text" for="Name" /> |
20 |
| - <validation-message for="Name" tag="div" /> |
| 31 | + <input type="text" for="Name" style="color:blue" /> |
| 32 | + <span validation-for="Name" style="color:blue" /> |
21 | 33 | </div>
|
22 | 34 | </div>
|
23 | 35 | <div class="form-group">
|
24 | 36 | <label for="DateOfBirth" class="control-label col-md-2" />
|
25 | 37 | <div class="col-md-10">
|
26 |
| - <input type="date" for="DateOfBirth" format="{0:d}" /> |
27 |
| - <validation-message for="DateOfBirth">How old are you?</validation-message> |
| 38 | + @* will automatically infer type="date" (reused HTML attribute) and format="{0:d}" (optional bound attribute) *@ |
| 39 | + <input for="DateOfBirth" /> |
| 40 | + <span validation-for="DateOfBirth">How old are you?</span> |
28 | 41 | </div>
|
29 | 42 | </div>
|
30 | 43 | <div class="form-group">
|
31 | 44 | <label for="YearsEmployeed" class="control-label col-md-2" />
|
32 | 45 | <div class="col-md-10">
|
| 46 | + @* <select/> tag helper has ContentBehavior.Append -- items render after static options *@ |
33 | 47 | <select for="YearsEmployeed" items="(IEnumerable<SelectListItem>)ViewBag.Items" size="2" class="form-control">
|
| 48 | + @* schedule-wise option tag helper (which adds "selected" attribute to static <option/>s) comes after helpers *@ |
| 49 | + @* - static use of "selected" attribute may cause HTML errors if in a single-selection <select/> *@ |
| 50 | + @* - @NTaylorMullen thinks <option/> tag helper could tell <select/> helper not to select anything from "items" *@ |
| 51 | + @* - wouldn't help if user selected one static <option/> and expression indicated another, especially one earlier in the <select/> *@ |
| 52 | + @* - may need a "default" bound parameter on the <select/> to avoid these cases and maintain "don't override" *@ |
| 53 | + <option value="" selected="selected">Why didn't you select anything?</option> |
34 | 54 | <optgroup label="Newby">
|
35 | 55 | <option value="0">Less than 1</option>
|
36 | 56 | <option value="1">1</option>
|
|
41 | 61 | <option value="5">5</option>
|
42 | 62 | <option value="6">6</option>
|
43 | 63 | </select>
|
44 |
| - <validation-message for="YearsEmployeed" tag="div" /> |
| 64 | + |
| 65 | + @* targets only <span/> in Beta; does not support equivalent of Html.ValidationMessageFor()'s tag parameter *@ |
| 66 | + @* - may eventually either support additional tags e.g. <p/> and <div/> or all tags /> *@ |
| 67 | + <span validation-for="YearsEmployeed" /> |
45 | 68 | </div>
|
46 | 69 | </div>
|
47 | 70 | <div class="form-group">
|
48 | 71 | <label for="Blurb" class="control-label col-md-2" />
|
49 | 72 | <div class="col-md-10">
|
50 | 73 | <textarea rows="4" for="Blurb"></textarea>
|
51 |
| - <validation-message for="Blurb" tag="div" /> |
| 74 | + <span validation-for="Blurb" /> |
52 | 75 | </div>
|
53 | 76 | </div>
|
54 | 77 |
|
55 | 78 | <div class="form-group">
|
56 | 79 | <div class="col-md-offset-2 col-md-10">
|
| 80 | + @* this <input/> lacks a "for" attribute and will not be changed by the <input/> tag helper *@ |
57 | 81 | <input type="submit" value="Create" class="btn btn-default" />
|
58 | 82 | </div>
|
59 | 83 | </div>
|
|
0 commit comments