From 13ce1a8c8174291ea451e6e1dca9e096d0ca64f0 Mon Sep 17 00:00:00 2001 From: sqozz Date: Sun, 15 Feb 2015 05:43:17 +0100 Subject: [PATCH] first javascript form validation implementation --- static/js/create.js | 22 +++++++++++++++++++--- templates/create.html | 12 ++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/static/js/create.js b/static/js/create.js index 1ab1679..7d23a19 100644 --- a/static/js/create.js +++ b/static/js/create.js @@ -71,10 +71,10 @@ function fillDropdownByValue(value, dropdownToFill) { // Hides the default browser-upload-form and replaces it by an button function customizeUploadButton() { - $(".tfile").before(''); - $(".tfile").hide(); + $("input.file").before(''); + $("input.file").hide(); $('body').on('click', '#button-file', function() { - $(".tfile").trigger('click'); + $("input.file").trigger('click'); }); } @@ -97,6 +97,22 @@ function setDropdownButtonText(text, dropdownButton) { dropdownTextSpan.innerHTML = text } +function validateForm() { + valid = true + file = document.querySelectorAll("input.file")[0] + category = document.querySelectorAll("input.category")[0] + subcategory = document.querySelectorAll("input.subcategory")[0] + torrentname = document.querySelectorAll("input.name")[0] + description = document.querySelectorAll("textarea.description")[0] + if(file.value.length <= 0) { valid = false } + if(category.value.length <= 0) { valid = false } + if(subcategory.value.length <= 0) { valid = false } + if(torrentname.value.length <= 0) { valid = false } + if(description.value.length <= 0) { valid = false } + + return false; +} + function chunk(string, n) { var ret = ""; for(var i=0, len=string.length; i < len; i += n) { diff --git a/templates/create.html b/templates/create.html index 0859cfc..bac269b 100644 --- a/templates/create.html +++ b/templates/create.html @@ -18,13 +18,13 @@ vim: ts=2 noexpandtab {% endfor %} {% endif %} -
+
{{ getLocalString(language, "torrent_file") }}
- +
@@ -38,7 +38,7 @@ vim: ts=2 noexpandtab
- +
@@ -98,7 +98,7 @@ vim: ts=2 noexpandtab {{ getLocalString(language, "description") }}
- +