diff --git a/app/assets/javascripts/hospital_necessities.js b/app/assets/javascripts/hospital_necessities.js index 8f4bc85..346de88 100644 --- a/app/assets/javascripts/hospital_necessities.js +++ b/app/assets/javascripts/hospital_necessities.js @@ -1,30 +1,34 @@ -//= require services/validate_form_service - -// ready(function(){ -// var hospitalNecessityPage = (function(){ -// -// var initialize = function(){ -// validateForm(); -// }; -// -// var validateForm = function(){ -// -// debugger -// var inputNumber = document.getElementsByClassName('js-necessityInput')[0]; -// -// inputNumber.addEventListener("focusout", function(){ -// for(var i = 0; i < 8; i++){ -// validateFormService.validatePositiveNumber(document.getElementsByClassName('js-necessityInput')[i]); -// } -// }) -// -// }; -// -// var animateModal = function(){ -// -// } -// -// initialize(); -// -// })() -// }) +// = require services/validate_form_service + +ready(function(){ + var hospitalNecessityPage = (function(){ + + + var initialize = function(){ + validateForm(); + }; + + var validateForm = function(){ + + var allInputNumbers = document.getElementsByClassName('js-necessityInput'); + for(var i = 0; i < 8; i++){ + var inputNumber = allInputNumbers[i]; + inputNumber.addEventListener("focusout", function(){ + validateFormService.validatePositiveNumber(); + }) + } + }; + + function myFunction(i){ + alert(i); + validateFormService.validatePositiveNumber(i); + } + + var animateModal = function(){ + + } + + initialize(); + + })() +}) diff --git a/app/assets/javascripts/services/validate_form_service.js b/app/assets/javascripts/services/validate_form_service.js index 77eabc6..f1e2e18 100644 --- a/app/assets/javascripts/services/validate_form_service.js +++ b/app/assets/javascripts/services/validate_form_service.js @@ -126,11 +126,13 @@ var validateFormService = (function(){ }, - validatePositiveNumber: function(inputNumber){ - // var inputNumber = document.getElementsByClassName('js-necessityInput'); - if(inputNumber.value < 0){ - alert("Por favor, utilize apenas nĂºmeros maiores que 0!"); - inputNumber.value = null; + validatePositiveNumber: function(){ + var inputNumber = document.getElementsByClassName('js-necessityInput'); + for(var i = 0; i < 8; i++){ + if(inputNumber[i].value < 0){ + alert("Por favor, utilize apenas nĂºmeros maiores que 0!"); + inputNumber[i].value = null; + } } } } diff --git a/app/views/hospital_necessities/_form.html.erb b/app/views/hospital_necessities/_form.html.erb index ba70760..8994e33 100644 --- a/app/views/hospital_necessities/_form.html.erb +++ b/app/views/hospital_necessities/_form.html.erb @@ -35,7 +35,7 @@