I have a fieldset that requires the user to enter some data like name, emai land phone number like this:
<h2 class="fs-title">Personal data</h2>
<input type="text" name="firstname" id="firstname" placeholder="First Name" class="textbox" ng-model="firstName"required/>
<input type="text" name="lastname" id="lastname" placeholder="Last Name" class="textbox" ng-model="lastName" required/>
<input type="email" name="email" class="textbox" placeholder="Email" ng-model="user.email" required>
<input type="text" name="contact" placeholder="Phone number" id="contact" ng-model="phoneNumber" required/>
<input type="button" name="next" class="next action-button" value="Next"/>
The class next
has a function associated to it:
var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches
$(".next").click(function(){
if(animating) return false;
animating = true;
current_fs = $(this).parent();
next_fs = $(this).parent().next();
//activate next step on progressbar using the index of next_fs
$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
//show the next fieldset
next_fs.show();
//hide the current fieldset with style
current_fs.animate({opacity: 0}, {
step: function(now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale current_fs down to 80%
scale = 1 - (1 - now) * 0.2;
//2. bring next_fs from the right(50%)
left = (now * 50)+"%";
//3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({
'transform': 'scale('+scale+')',
'position': 'absolute'
});
next_fs.css({'left': left, 'opacity': opacity});
},
duration: 800,
complete: function(){
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
// easing: 'easeInOutBack'
linear: 'easeInOutBack'
});
});
In its current state, you can click Next even if the form is not properly completed, even if it's full empty and I don't want that. I want when I click next, to also check if the inputs are properly filled and if not, under each field, a message/warning ot be displayed about what the problem is (ie. on email, it has to contain a @)
I tried using the btn btn-primary classes from bootstrap but if I use them (they do validation as I want) I can't use my next class anymore. Any ideas how to make it work? I tried Angular directives, like ng-disable on condition that those fields are empty but for some reason, if I fill the fields, the button still doesn't work so how can I use btn btn-primary and still have my next class work?