We a custom field which is a multi select text field and wiki rendered,
We have added an AJS code as html as below,
<script>
AJS.$(document).ready(function() {
AJS.$("#rowForcustomfield_10503").css({"width":"130%"});
AJS.$('.confluenceTable').find('tr').each(function() {
var tds = AJS.$(this).find('th');
var len = tds.length;
for (var i = 0; i < len; i++) { AJS.$(tds[i]).css('text-align', 'center'); AJS.$(tds[i]).css('color', 'white'); AJS.$(tds[i]).css('background-color', '#5F5F5F '); }
});
window.alert("Hi");
var ths = AJS.$("table tbody tr").find("th");
var len = ths.length;
for (var i = 0; i < len; i++) {
AJS.$(ths[i]).css({"width":"1px","white-space":"nowrap"});
}
AJS.$('.confluenceTable').find('tr').each(function() {
AJS.$(this).css('background-color', '#F2F2F2 ');
AJS.$(this).css('background-color', '#F1F1F1 ');
var tds = AJS.$(this).find('td');
var len = tds.length;
for (var i = 0; i < len; i++) {
AJS.$(tds[i]).css('text-align', 'center');
AJS.$(tds[i]).css('color', 'black');
AJS.$(tds[i]).css({"width":"1px","white-space":"nowrap"});
}
});
It was coming with wrapping and misaligned. Hence we ran it in console and it worked, the custom field came no wrapped and worked fine. We have added a window.alert("Hi") to test and it displayed when run in console and when we edited the custom field.
BUT not while loading page. Please help
Did you really paste the whole script? It's missing last two rows:
});
</script>
Also, another problem might be different location from where the JS is loaded. Try to put the code not into the Custom Field's description but into Custom Field's description under the Field Configuration Scheme. See this Atlassian Knowledge Base.
I'm attempting to add data-webpart attributes to all the anchors within a document, but populate their values with the data attributes of their containing divs.
However the code I wrote appears to be populating all of the anchors with only one of the data attributes (or rather, adding the first one to all, then adding the second).
Any help would be much appreciated!
HTML
<body>
<div data-webpart="form">
Test Link
Test Link
Test Link
</div>
<div data-webpart="icon-grid">
Test Link
Test Link
Test Link
</div>
</body>
JavaScript
// data attributer
var webParts = document.querySelectorAll("[data-webpart]");
var webPartAnchors = document.querySelectorAll("[data-webpart] > a");
function addDataAttr() {
var closestWebPartAttr;
for (i = 0; i < webPartAnchors.length; i++) {
for (e = 0; e < webParts.length; e++) {
closestWebPartAttr = webParts[e].getAttribute("data-webpart");
webPartAnchors[i].setAttribute("data-web-part", closestWebPartAttr);
}
}
}
window.onload = function() {
if (webParts !== null) { addDataAttr(); }
};
Your nested loops are copying the data attribute from every DIV to every anchor, because there's nothing that relates each anchor to just their parent. At the end they all have the last data attribute.
Since the anchors are direct children of the DIV, you don't need to use querySelectorAll() to get them, you can just use .children() within the loop.
function addDataAttr() {
for (var i = 0; i < webParts.length; i++) {
var webpart = webParts[i].dataset.webpart;
var children = webParts[i].children;
for (var j = 0; j < children.length; j++) {
children[j].dataset.webpart = webpart;
}
}
}
I am trying to get a value of a cell in a html table within JavaScript. I can do this when the row is clicked twice or when I click on a row and then another row but I need to get the cell value on first click
This is my code so far
var table = document.getElementById('ContentPlaceHolder1_htmltable');
if (table != null) {
for (var i = 0; i < table.rows.length; i++) {
for (var j = 0; j < table.rows[i].cells.length; j++)
table.rows[i].cells[j].onclick = function () {
cellvalue = this.innerHTML;
};
}
}
This runs on an onclick event on the ASPxListBox object from devexpress I am using.
Note: I can't use third party libraries like jQuery for this.
Thanks
The jsfiddle code posted by arcade Gandalf above does work, however, to fix my problem of getting the cell value on first click, the code needs to run when the page load is complete
window.onload = getCellValueOfTable;
function getCellValueOfTable {
jsFiddle code or my code posted above...
}
Then in the onclick event for the listbox or a table as I described in the question, just call the above function and that is all.
I am loading the grid inside a popup, having ok button at the bottom of the grid,after data load I want to select the row from the grid and click on 'ok' button to assign the value in a textbox and hide the popup.
using clientside event for this. my code below.
function OnSearchADSOk(s, e) {
e.processOnServer = false;
grdSearchADSUser.GetSelectedFieldValues('UserName;FirstName;LastName;EmailAddress;KeyId', GetSearchADSSelectedValues);
}
grdSearchADSUser.GetSelectedFieldValues not fetching values from the grid.
GetSelectedFieldValues doesn't return any selected values from the grid. You should process values in the GetSearchADSSelectedValues function. Code below from the already answered post should be
function GetSearchADSSelectedValues(result) {
for(var i = 0; i < result.length; i ++)
for(var j = 0; j <result[i].length; j++) {
alert(result[i][j]);
}
}
How can we disable all the elements in html through javascript.The easiest way...
I suggest to do it the "Lightbox"-style way.
Add an absolute positioned, transparent, full screen div Layer above the Page.
This way, the user can't even click on a Link.
To give the user a visual feedback that the page is disabled,
you can make the div e. g. 50% transparent black.
BTW, here is also a jQuery Plugin that uses a similar technique.
The easiest way is to put all form elements you want to disable inside a <fieldset> and then disable the fieldset itself.
An example: http://jsfiddle.net/xdkf9b8j/1/
If you don't want the border around the fieldset, remove it per css.
Try this,
function disableForm(theform) {
if (document.all || document.getElementById) {
for (i = 0; i < theform.length; i++) {
var formElement = theform.elements[i];
if (true) {
formElement.disabled = true;
}
}
}
}
Or else you can try this too, as RaYell said
function disableForm() {
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
inputs[i].disabled = true;
}
var selects = document.getElementsByTagName("select");
for (var i = 0; i < selects.length; i++) {
selects[i].disabled = true;
}
var textareas = document.getElementsByTagName("textarea");
for (var i = 0; i < textareas.length; i++) {
textareas[i].disabled = true;
}
var buttons = document.getElementsByTagName("button");
for (var i = 0; i < buttons.length; i++) {
buttons[i].disabled = true;
}
}
To disable the whole page you can find some info here,
I don't know why you would need that but this will work:
// this will disable all input elements
var elems = document.getElementsByTagName('input');
var len = elems.length;
for (var i = 0; i < len; i++) {
elems[i].disabled = true;
}
All the form elements (inputs, selects, textareas) within a form, are accesible through the form.elements HTMLCollection, you can iterate the collection disabling each element:
function disableForm(form) {
var length = form.elements.length,
i;
for (i=0; i < length; i++) {
form.elements[i].disabled = true;
}
}
Usage examples:
disableForm(document.forms[0]);
disableForm(document.getElementById('formId'));
Once i had to create a tutorial for my website. I needed to disable all interactions on a page excluding some elements. To do so i used this method:
First make sure to remove all events bindings from your page elements. You can do this by using:
$('*').unbind();
Next disable all links on your page:
$('a').each(function(){$(this).click(function(){return false;})});
and disable all inputs:
$('input').attr('disabled', true);
The code needs to be executed at the end of your document. BTW you may exclude some elements within jquery selector to keep them active.
To lock:
var controls = document.querySelectorAll("button, input, select, textarea");
for (var c of controls) {
c.disabled = true;
}
To unlock:
var controls = document.querySelectorAll("button, input, select, textarea");
for (var c of controls) {
c.disabled = false;
}
That simple.
Just and without crutches!
/**
* Enable/disable all form controlls
* #param status Status: true - form active, false - form unactive
*/
HTMLFormElement.prototype.setStatus = function (status) {
for (var i in this.elements) {
this.elements[i].disabled = !status;
}
};
// Example:
var my_form = document.getElementById('my_form_with_many_inputs');
my_form.setStatus(false); // Disable all inputs in form
my_form.setStatus(true); // Enable all inputs in form
Depending what result you need you could also do
`document.getElementById('main_form').style.display = 'none';`
Where main_form is the id of your form. You can use the same technique to hide a div containing whatever elements you want to disable.
The best way is to add a div with highest z-index having width:100% and height:100%.It will cover your entire page and make everything not clickable means disabled virtually.It is best,because it will not use any loop and any complex code.