Skip to content

Commit

Permalink
Move JS out of html
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Oct 22, 2021
1 parent bbf2cc1 commit 1587663
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
33 changes: 2 additions & 31 deletions core/src/main/resources/lib/hudson/newFromList/form.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,7 @@ THE SOFTWARE.
${%Create}
</button>
</div>
</s:form>

<script><![CDATA[
function updateOk() {
function state() {
let form = document.getElementById("createItemForm");
let nameInput = document.getElementById("name");
let radios = form.querySelectorAll('input[type="radio"]');
if (nameInput.value.length === 0) {
return true;
}
// this means we only have dummy checkboxes
if (radios.length === 2) {
return true;
}

for (i = 0; i < radios.length; i++) {
if (radios[i].checked) {
return false;
}
}
return true;
}
document.getElementById("ok").disabled = state();
}
updateOk();
]]></script>
<st:adjunct includes="lib.hudson.newFromList.validation" />
</s:form>
</j:jelly>
28 changes: 28 additions & 0 deletions core/src/main/resources/lib/hudson/newFromList/validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function updateOk() {
function state() {
let form = document.getElementById("createItemForm");
let nameInput = document.getElementById("name");
let radios = form.querySelectorAll('input[type="radio"]');

if (nameInput.value.length === 0) {
return true;
}

// this means we only have dummy checkboxes
if (radios.length === 2) {
return true;
}

for (i = 0; i < radios.length; i++) {
if (radios[i].checked) {
return false;
}
}

return true;
}

document.getElementById("ok").disabled = state();
}

updateOk();

0 comments on commit 1587663

Please sign in to comment.