Inject Tag for Label element by JQuery

Jquery doesn’t work well with for attribute of <label>, $(‘label[for=”reporter”]’) will null.


var OnlyForCreateRecord = function() {
var pageText = $('h2.aui-popup-heading').text();
if (pageText.indexOf("Create Record") >= 0) {
var InsertAsterisk = function() {
var fieldNames = [ 'issuetype', 'reporter', 'summary', 'customfield_10200' ];


for (var index in fieldNames)
{ // return the first sibling label element
var requiredLabel = $("[name*='" + fieldNames[index] + "']").siblings('label').first();
if ($(requiredLabel).children('span').length <= 0)
{
$(requiredLabel).append("<span class='aui-icon icon-required' />");
//alert("Injecting Validation for Field: " + fieldNames[index]);
}
}
};

// since the fields are rendered by javascript also, make sure the fields have been presented.
setTimeout(InsertAsterisk, 500);
}
}
setTimeout(OnlyForCreateRecord, 250);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s