Skip to content

Instantly share code, notes, and snippets.

@jeffhandley
Created November 3, 2011 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffhandley/1338049 to your computer and use it in GitHub Desktop.
Save jeffhandley/1338049 to your computer and use it in GitHub Desktop.
Help name this
<!-- 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>
@InfinitiesLoop
Copy link

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).

@jpoehls
Copy link

jpoehls commented Nov 4, 2011

is Validation.GetApplicableCssStyleBasedOnValidationState() long enough? ;)

@InfinitiesLoop
Copy link

^^
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 :)

@jeffhandley
Copy link
Author

I think GetApplicableCssStyleBasedOnValidationState is the winner

for the longest proposed name contest.

@jeffhandley
Copy link
Author

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; } }

@InfinitiesLoop
Copy link

Yeah. Although, I suggest :)

ctor() {
ClassForValidFields = string.Empty;
ClassForInvalidFields = "invalid";
}
public string ClassForValidFields { get; set; }
public string ClassForInvalidFields { get; set; }

@jeffhandley
Copy link
Author

Thanks guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment