As part of the doco-loco assessment, the group decided to use a jQuery validator to check input fields.
Doco-Loco feedback from
For the feedback from I was required to use the validator to make that every field was filled out otherwise the form would not submit. Following the documentation on the website I wrote out the needed code in order to make it work and when I tested it, it didn’t seem to pass the script at all. From here I filled around with the data-validation=”” in case I was missing something or forgot to add a piece of code. When that didn’t work I went in search for similar problems and solutions of google. here I found a lot of helpful information but none of them helped me when I tried them. After this, I decided to look through the other files in the directory to see if they had code that I didn’t. I found some code to call the validation script that was different from what I had been trying and it looked promising.
var form = $(‘form#aca_form’);
$.validate({
form : form,
});
Finally the validation worked! however, on closer inspection it came to my attention that the form was submitting even though the users hadn’t filled out the fields. So the validation was half working it was detecting that there was an error just not stopping them from submitting the form. From here I realised that I was activating the validation on the “click” of the submit button rather than on when it submitted the whole form.
$(“#aca_form #submit”).on(‘submit’, function() {
academic_form();
});
Using this code fixed the problem.
Split function while checking for specific email domain
As part of the login from the user was asked to use their SAE email such meant that as developers had to find a way to make sure that the email domain was SAE. For this I used a split function. This function splits strings based on what is inside the split(”); function. Therefore, I could use this to detect the domain on the end of the email and check if it was either a teacher or a student as well as making sure it was an SAE email. I tried adding this onto the end of the web-page but when this didn’t work I placed the code inside the validation file. Which unsurprisingly didn’t work either. In the end it was a lot simpler than I thought it would be I just had to add the two specific strings to the existing validtation function.
var emailParts = email.toLowerCase().split(‘@’),
localPart = emailParts[0],
domain = emailParts[1];
var email_student = “student.sae.edu.au”;
var email_staff = “sae.edu”;
if (localPart && domain && domain == email_student || localPart && domain && domain == email_staff) {if( localPart.indexOf(‘”‘) === 0 ) {
var len = localPart.length;
localPart = localPart.replace(/\”/g, ”);
if( localPart.length !== (len-2) ) {
return false; // It was not allowed to have more than two apostrophes
}
}
Amped UP
On on of the pages I was getting the users to submit a form that registered their band. I felt that this needed to have validation and why not practice with the jQuery validation I already had? This worked with minimal problems as the standard $.validate(); script seemed to call the function.