Created
April 29, 2015 01:20
-
-
Save RyannosaurusRex/2901edaade59323c4afc to your computer and use it in GitHub Desktop.
Mark Fields as Required
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Checks an element to see if the validation says it is required | |
// and if so, adds a '*' to the label using the 'for' semantic attribute. | |
function MarkAsRequired(element) { | |
var req = $(element).attr('data-val-required'); | |
if (undefined != req) { | |
var label = $('label[for="' + $(element).attr('id') + '"]'); | |
var text = label.text(); | |
if (text.length > 0) { | |
label.append('<span style="color:red"> *</span>'); | |
} | |
} | |
}; | |
// EXAMPLE USAGE | |
// Setup the required markers for each type of input item. | |
$('input').each(function () { | |
MarkAsRequired(this); | |
}); | |
$('select').each(function () { | |
MarkAsRequired(this); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment