Skip to content

Instantly share code, notes, and snippets.

@salsalabs
Last active December 7, 2015 01:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salsalabs/cae48a4bf52030507194 to your computer and use it in GitHub Desktop.
Save salsalabs/cae48a4bf52030507194 to your computer and use it in GitHub Desktop.
Script to change the label for a field. Works on all Salsa pages, including actions
<script>
// You configure this. Fill in the parts between the quoation marks.
// Usual rules apply:
//
// 1. Contents cannot contain quotation marks.
// 2. Do not disturb the punctuation.
//
var currentFieldLabel = "Organization";
var newFieldLabel = "Business or Organization Name";
// If you need to change more than one field, then stop here and send
// a message to support@salsalabs.com. We'll be glad to help.
//
document.addEventListener('DOMContentLoaded', function(){
// Change the contents of the specified label. Assumes that the
// label is visible on the page.
// @return [Boolean] returns true if the field was changed
//
function changeLabel() {
var labels = document.getElementsByTagName('label');
for (var j = 0; j < labels.length; j++ ) {
if (labels[j].firstChild.data == currentFieldLabel) {
labels[j].firstChild.data = newFieldLabel;
return true;
}
}
return false;
}
// If this is a targeted action, then wait for the field to appear.
// Targeted actions use AJAX to load sub-pages. Input fields do not
// appear on the page loaded by the browser.
//
if (RegExp('action_KEY=\\d+').test(window.location.href)) {
var interval = null;
var actor = function() {
if (changeLabel() ) {
clearTimeout(interval);
}
}
interval = setInterval(actor, 300);
} else {
changeLabel();
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment