-
-
Save jeffhandley/1338049 to your computer and use it in GitHub Desktop.
<!-- What you can do today --> | |
<label for="firstname" class="@(ModelState.IsValidField("firstname") ? "" : "invalid")">First Name</label> | |
<!-- A proposed helper method that needs a name --> | |
<label for="firstname" class="@Validation.InvalidClass("firstname", "invalid")">First Name</label> | |
<!-- With a property that defines the invalid class name, which could be defaulted to "invalid" --> | |
@{ Validation.InvalidClassName = "invalid"; } | |
<label for="firstname" class="@Validation.InvalidClass("firstname")">First Name</label> |
is Validation.GetApplicableCssStyleBasedOnValidationState() long enough? ;)
^^
Get -- unnecessary prefix
Applicable -- unnecessary token, implied
CssStyle -- implied by Class token and where used in markup
BasedOnValidationState -- what else would it be doing, and we already have context on "Validation."
Therefore, ClassFor or ClassForField works for me :)
I think GetApplicableCssStyleBasedOnValidationState is the winner
for the longest proposed name contest.
ClassFor seems good. With properties:
private string _classForInalidFields = "invalid";
public string ClassForInvalidFields { get { return _classForInvalidFields; } set { _classForInvalidFields = value; } }
private string _classForValidFields = String.Empty;
public string ClassForValidFields { get { return _classForValidFields; } set { _classForValidFields = value; } }
Yeah. Although, I suggest :)
ctor() {
ClassForValidFields = string.Empty;
ClassForInvalidFields = "invalid";
}
public string ClassForValidFields { get; set; }
public string ClassForInvalidFields { get; set; }
Thanks guys!
Validation.ClassFor
Validation.ClassForField
You may even want a valid class in some scenarios (for a good, required field, versus a normal unrequired field, for example).