first javascript form validation implementation

This commit is contained in:
sqozz
2015-02-15 05:43:17 +01:00
parent 9ec244d9f3
commit 13ce1a8c81
2 changed files with 25 additions and 9 deletions

View File

@ -71,10 +71,10 @@ function fillDropdownByValue(value, dropdownToFill) {
// Hides the default browser-upload-form and replaces it by an button
function customizeUploadButton() {
$(".tfile").before('<button id="button-file" type="button" class="btn btn-default"><span class="text">Upload...</span><span class="glyphicon glyphicon-open-file" aria-hidden="true"></span></button>');
$(".tfile").hide();
$("input.file").before('<button id="button-file" type="button" class="btn btn-default"><span class="text">Upload...</span><span class="glyphicon glyphicon-open-file" aria-hidden="true"></span></button>');
$("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) {