Skip to content
This repository has been archived by the owner on Apr 5, 2020. It is now read-only.

Commit

Permalink
#3<@mathiasVoelcker, @callegas> - criar validacao de inputs no form d…
Browse files Browse the repository at this point in the history
…e necessidade
  • Loading branch information
mathiasVoelcker committed Oct 11, 2016
1 parent a84d584 commit 69abf7c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
64 changes: 34 additions & 30 deletions app/assets/javascripts/hospital_necessities.js
Original file line number Diff line number Diff line change
@@ -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();

})()
})
12 changes: 7 additions & 5 deletions app/assets/javascripts/services/validate_form_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/hospital_necessities/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<div class="Container-section">
<div class="Input Input--large">
<label class="Input-label u-size3of12">A+</label>
<%= f.number_field :a_positive, min: "0", max: "100", class: "Input-value u-size4of12 js-necessityInput" %>
<%= f.number_field :a_positive, min: "0", max: "100", class: "Input-value u-size4of12 js-necessityInput", click: "myFunction()"%>
<span class="Input-description u-size4of12">doadores</span>
</div>

Expand Down

0 comments on commit 69abf7c

Please sign in to comment.