How to use elementHandler method in storybook-test-runner

Best JavaScript code snippet using storybook-test-runner

validation.js

Source:validation.js Github

copy

Full Screen

1/* Shubha Ravikumar, FNU Account: jadrn0462CS545, Fall 20143Project #2 */4function isEmpty(fieldValue) {5 return $.trim(fieldValue).length == 0;6}7function isValidStateAbbr(state) {8 var stateList = new Array("AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC",9 "DC2", "DE", "FL", "GA", "GU", "HI", "IA", "ID", "IL", "IN", "KS",10 "KY", "LA", "MA", "MD", "ME", "MH", "MI", "MN", "MO", "MS", "MT",11 "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR",12 "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA",13 "WI", "WV", "WY");14 for (var i = 0; i < stateList.length; i++)15 if (stateList[i] == $.trim(state.toUpperCase()))16 return true;17 return false;18}19function isValidEmail(emailAddress) {20 var pattern = new RegExp(21 /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);22 return pattern.test(emailAddress);23}24$(document)25 .ready(26 function() {27 var elementHandle = new Array(28);28 var errorStatusHandle = new Array(28);29 // Handlers to access elements :-30 // Parent basic Info handlers31 elementHandle[0] = $('[name="parentFirstName"]');32 elementHandle[1] = $('[name="parentLastName"]');33 elementHandle[2] = $('[name="pmArea"]');34 elementHandle[3] = $('[name="pmPrefix"]');35 elementHandle[4] = $('[name="pmPhone"]');36 elementHandle[5] = $('[name="phArea"]');37 elementHandle[6] = $('[name="phPrefix"]');38 elementHandle[7] = $('[name="phPhone"]');39 // Parent additional info handlers40 elementHandle[8] = $('input[name=relationship]:checked');41 elementHandle[9] = $('[name="addressLine1"]');42 elementHandle[10] = $('[name="city"]');43 elementHandle[11] = $('[name="state"]');44 elementHandle[12] = $('[name="postcode"]');45 elementHandle[13] = $('[name="email"]');46 // Child info handlers47 elementHandle[14] = $('[name="childFirstName"]');48 elementHandle[15] = $('[name="childLastName"]');49 elementHandle[16] = $('[name="photo"]');50 elementHandle[17] = $('[name="gender"]');51 elementHandle[18] = $('[name="dob"]');52 // Child additional info handlers53 elementHandle[19] = $('[name="scArea"]');54 elementHandle[20] = $('[name="scPrefix"]');55 elementHandle[21] = $('[name="scPhone"]');56 elementHandle[22] = $('[name="childNickName"]');57 elementHandle[23] = $('[name="secondaryContactName"]');58 // Error Status59 // Parent basic Info error status60 errorStatusHandle[0] = $('#parentFirstNameErrMsg');61 errorStatusHandle[1] = $('#parentLastNameErrMsg');62 errorStatusHandle[2] = $('#cellPhoneErr');63 errorStatusHandle[3] = $('#telPhoneErr');64 // Parent additional info error status65 errorStatusHandle[4] = $('#relationshipErrMsg');66 errorStatusHandle[5] = $('#addressErrMsg');67 errorStatusHandle[6] = $('#cityErrMsg');68 errorStatusHandle[7] = $('#stateErrMsg');69 errorStatusHandle[8] = $('#postCodeErrMsg');70 errorStatusHandle[9] = $('#emailErrMsg');71 // Child info error status72 errorStatusHandle[10] = $('#childFirstNameErrMsg');73 errorStatusHandle[11] = $('#childLastNameErrMsg');74 errorStatusHandle[12] = $('#imgFormatErrMsg');75 errorStatusHandle[13] = $('#genderErrMsg');76 errorStatusHandle[14] = $('#dateErrMsg');77 // Child additional info error status78 errorStatusHandle[15] = $('#scTelPhoneErrMsg');79 errorStatusHandle[16] = $('#nicknameErrMsg');80 errorStatusHandle[17] = $('#scNameErrMsg');81 function setErrorStatus(elementHandler, errorStatusHandle,82 msg) {83 errorStatusHandle.addClass("error");84 errorStatusHandle.text(msg);85 elementHandler.focus();86 }87 function validateNonEmptyField(elementHandler,88 errorStatusHandle, msg) {89 if (isEmpty(elementHandler.val())) {90 setErrorStatus(elementHandler, errorStatusHandle,91 msg);92 return false;93 }94 return true;95 }96 function isValidName() {97 var isValid = true;98 if (validateNonEmptyField(elementHandle[23],99 errorStatusHandle[17],100 "Please enter the name") == false) {101 isValid = false;102 }103 if (validateNonEmptyField(elementHandle[22],104 errorStatusHandle[16],105 "Please enter the nickname") == false) {106 isValid = false;107 }108 if (validateNonEmptyField(elementHandle[15],109 errorStatusHandle[11],110 "Please enter the last name") == false) {111 isValid = false;112 }113 if (validateNonEmptyField(elementHandle[14],114 errorStatusHandle[10],115 "Please enter the first name") == false) {116 isValid = false;117 }118 if (validateNonEmptyField(elementHandle[1],119 errorStatusHandle[1],120 "Please enter the last name") == false) {121 isValid = false;122 }123 if (validateNonEmptyField(elementHandle[0],124 errorStatusHandle[0],125 "Please enter the first name") == false) {126 isValid = false;127 }128 return isValid;129 }130 function isValidAreaCode(elementHandler, errorStatusHandle) {131 if (isEmpty(elementHandler.val())) {132 setErrorStatus(elementHandler, errorStatusHandle,133 "Please enter the area code");134 return false;135 }136 if (!$.isNumeric(elementHandler.val())) {137 setErrorStatus(elementHandler, errorStatusHandle,138 "The area code is invalid, numbers only");139 return false;140 }141 if (elementHandler.val().length != 3) {142 setErrorStatus(elementHandler, errorStatusHandle,143 "The area code must have three digits");144 return false;145 }146 return true;147 }148 function isValidPrefix(elementHandler, errorStatusHandle) {149 if (isEmpty(elementHandler.val())) {150 setErrorStatus(elementHandler, errorStatusHandle,151 "Please enter the phone number prefix");152 return false;153 }154 if (!$.isNumeric(elementHandler.val())) {155 setErrorStatus(elementHandler, errorStatusHandle,156 "The prefix is invalid, numbers only");157 return false;158 }159 if (elementHandler.val().length != 3) {160 setErrorStatus(elementHandler, errorStatusHandle,161 "The prefix must have three digits");162 return false;163 }164 return true;165 }166 function isValidPhone(elementHandler, errorStatusHandle) {167 if (isEmpty(elementHandler.val())) {168 setErrorStatus(elementHandler, errorStatusHandle,169 "Please enter the phone number");170 return false;171 }172 if (!$.isNumeric(elementHandler.val())) {173 setErrorStatus(elementHandler, errorStatusHandle,174 "The phone code is invalid, numbers only");175 return false;176 }177 if (elementHandler.val().length != 4) {178 setErrorStatus(elementHandler, errorStatusHandle,179 "The phone code must have four digits");180 return false;181 }182 return true;183 }184 function isvalidPhoneNumber() {185 var isValid = true;186 var isValidSContactNumber = false;187 if (isValidAreaCode(elementHandle[19],188 errorStatusHandle[15]) == true) {189 if (isValidPrefix(elementHandle[20],190 errorStatusHandle[15]) == true) {191 if (isValidPhone(elementHandle[21],192 errorStatusHandle[15]) == true) {193 isValidSContactNumber = true;194 }195 }196 }197 198 if (isValidSContactNumber == false) {199 isValid = false;200 }201 var isValidCellNumber = false;202 if (isValidAreaCode(elementHandle[2],203 errorStatusHandle[2]) == true) {204 if (isValidPrefix(elementHandle[3],205 errorStatusHandle[2]) == true) {206 if (isValidPhone(elementHandle[4],207 errorStatusHandle[2]) == true) {208 isValidCellNumber = true;209 }210 }211 }212 if (isValidCellNumber == false) {213 isValid = false;214 }215 var isValidTelNumber = false;216 if (isEmpty(elementHandle[5].val())217 && isEmpty(elementHandle[6].val())218 && isEmpty(elementHandle[7].val())) {219 isValidTelNumber = true;220 } else {221 if (isValidAreaCode(elementHandle[5],222 errorStatusHandle[3]) == true) {223 if (isValidPrefix(elementHandle[6],224 errorStatusHandle[3]) == true) {225 if (isValidPhone(elementHandle[7],226 errorStatusHandle[3]) == true) {227 isValidTelNumber = true;228 }229 }230 }}231 if (isValidTelNumber == false) {232 isValid = false;233 }234 return isValid;235 }236 function isValidEmailAddress(elementHandler,237 errorStatusHandler) {238 if (isEmpty(elementHandler.val())) {239 setErrorStatus(elementHandler, errorStatusHandler,240 "Please enter your email address");241 return false;242 }243 if (!isValidEmail(elementHandler.val())) {244 setErrorStatus(elementHandler, errorStatusHandler,245 "The email address appears to be invalid");246 return false;247 }248 return true;249 }250 function isValidState(elementHandler, errorStatusHandler) {251 if (isEmpty(elementHandler.val())) {252 setErrorStatus(elementHandler, errorStatusHandler,253 "Please enter your state");254 return false;255 }256 if (!isValidStateAbbr(elementHandler.val())) {257 setErrorStatus(elementHandler, errorStatusHandler,258 "Invalid state, please use the two letter state abbreviation");259 return false;260 }261 return true;262 }263 function isValidZipcode(elementHandler, errorStatusHandler) {264 if (isEmpty(elementHandler.val())) {265 setErrorStatus(elementHandler, errorStatusHandler,266 "Please enter your zip code");267 return false;268 }269 if (!$.isNumeric(elementHandler.val())) {270 setErrorStatus(elementHandler, errorStatusHandler,271 "Invalid zip code, numbers only please");272 return false;273 }274 if (elementHandler.val().length != 5) {275 setErrorStatus(elementHandler, errorStatusHandler,276 "The zip code must have five digits");277 return false;278 }279 return true;280 }281 function isValidImage(elementHandler, errorStatusHandler) {282 if (isEmpty(elementHandler.val())) {283 setErrorStatus(elementHandler, errorStatusHandler,284 "Please upload a photo in .jpg or .png format");285 return false;286 }287 288 if (elementHandler.val().length > 15) {289 setErrorStatus(elementHandler, errorStatusHandler,290 "File name cannot be more than 15 characters");291 return false;292 }293 var fileExtension = elementHandler.val().substr(294 elementHandler.val().length - 4).toLowerCase();295 if (!(fileExtension == ".jpg" || fileExtension == ".png")) {296 setErrorStatus(elementHandler, errorStatusHandler,297 "Please upload a photo in .jpg or .png format only");298 return false;299 }300 return true;301 }302 function isValidDate(elementHandler, errorStatusHandler) {303 if (isEmpty(elementHandler.val())) {304 setErrorStatus(elementHandler, errorStatusHandler,305 "Please enter date in mm/dd/yyyy format");306 return false;307 }308 // Declare Regex , Checks for dd/mm/yyyy format.309 var dateRegEx = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;310 if (!dateRegEx.test(elementHandler.val())) {311 setErrorStatus(elementHandler, errorStatusHandler,312 "Invalid date format. Enter in mm/dd/yyyy format");313 return false;314 }315 var dateParts = elementHandler.val().split("/");316 // now turn the three values into a Date object and317 // check them318 var dob = new Date(dateParts[2], dateParts[0] - 1,319 dateParts[1]);320 var checkDay = dob.getDate();321 var checkMonth = dob.getMonth() + 1;322 var checkYear = dob.getFullYear();323 if (!(dateParts[1] == checkDay324 && dateParts[0] == checkMonth && dateParts[2] == checkYear)) {325 setErrorStatus(elementHandler, errorStatusHandler,326 "Please enter a valid date");327 return false;328 }329 var endDate = new Date(2014, 5, 2);330 var diff = endDate.getTime() - dob.getTime();331 var yrs = Math.floor(diff332 / (1000 * 60 * 60 * 24 * 365.25));333 if (!(yrs >= 12 && yrs <= 18)) {334 setErrorStatus(elementHandler, errorStatusHandler,335 "Only children of age 12 to 18 are allowed");336 return false;337 }338 return true;339 }340 function isValidData() {341 var isValid = true;342 var selectedRelationship = $(343 'input[name=relationship]:checked').val();344 if (isEmpty(selectedRelationship)) {345 setErrorStatus(elementHandle[8],346 errorStatusHandle[4],347 "Please enter relationship");348 isValid = false;349 }350 var selectedGender = $('input[name=gender]:checked')351 .val();352 if (isEmpty(selectedGender)) {353 setErrorStatus(elementHandle[17],354 errorStatusHandle[13],355 "Please enter gender");356 isValid = false;357 }358 if (isValidDate(elementHandle[18],359 errorStatusHandle[14]) == false) {360 isValid = false;361 }362 if (isValidImage(elementHandle[16],363 errorStatusHandle[12]) == false) {364 isValid = false;365 }366 if (isValidZipcode(elementHandle[12],367 errorStatusHandle[8]) == false) {368 isValid = false;369 }370 if (isValidState(elementHandle[11],371 errorStatusHandle[7]) == false) {372 isValid = false;373 }374 if (isEmpty(elementHandle[10].val())) {375 setErrorStatus(elementHandle[10],376 errorStatusHandle[6],377 "Please enter your city");378 isValid = false;379 }380 if (isEmpty(elementHandle[9].val())) {381 setErrorStatus(elementHandle[9],382 errorStatusHandle[5],383 "Please enter your address");384 isValid = false;385 }386 if (isValidEmailAddress(elementHandle[13],387 errorStatusHandle[9]) == false) {388 isValid = false;389 }390 if (isvalidPhoneNumber() == false) {391 isValid = false;392 }393 if (isValidName() == false) {394 isValid = false;395 }396 return isValid;397 }398 // focus on 1st field on page load399 elementHandle[0].focus();400 // HANDLERS401 // on blur, if the user has entered valid data, the error402 // message should no longer show.403 function clearErrorStatus(elementHandler, errorStatusHandle) {404 if (isEmpty(elementHandler.val()))405 return;406 removeError(errorStatusHandle);407 }408 function removeError(errorStatusHandle) {409 errorStatusHandle.text("");410 errorStatusHandle.removeClass("error");411 }412 // clear status when parent first name is entered413 elementHandle[0].on('blur',414 function() {415 clearErrorStatus(elementHandle[0],416 errorStatusHandle[0]);417 });418 // clear status when parent last is entered419 elementHandle[1].on('blur',420 function() {421 clearErrorStatus(elementHandle[1],422 errorStatusHandle[1]);423 });424 // clear status when parent first name is entered425 elementHandle[22].on('blur',426 function() {427 clearErrorStatus(elementHandle[22],428 errorStatusHandle[16]);429 });430 431 // clear status when parent first name is entered432 elementHandle[23].on('blur',433 function() {434 clearErrorStatus(elementHandle[23],435 errorStatusHandle[17]);436 });437 elementHandle[2].on('blur', function() {438 if (isEmpty(elementHandle[2].val()))439 return;440 if (!isEmpty(errorStatusHandle[2].text())) {441 if (isValidAreaCode(elementHandle[2],442 errorStatusHandle[2]) == true) {443 if (isValidPrefix(elementHandle[3],444 errorStatusHandle[2]) == true) {445 if (isValidPhone(elementHandle[4],446 errorStatusHandle[2])) {447 removeError(errorStatusHandle[2]);448 }449 }450 }451 /*452 * if (isValidAreaCode(elementHandle[2],453 * errorStatusHandle[2])) {454 * removeError(errorStatusHandle[2]); }455 */456 }457 });458 elementHandle[3].on('blur', function() {459 if (isEmpty(elementHandle[3].val()))460 return;461 if (!isEmpty(errorStatusHandle[2].text())) {462 if (isValidAreaCode(elementHandle[2],463 errorStatusHandle[2]) == true) {464 if (isValidPrefix(elementHandle[3],465 errorStatusHandle[2]) == true) {466 if (isValidPhone(elementHandle[4],467 errorStatusHandle[2])) {468 removeError(errorStatusHandle[2]);469 }470 }471 }472 473 }474 });475 elementHandle[4].on('blur', function() {476 if (isEmpty(elementHandle[4].val()))477 return;478 if (!isEmpty(errorStatusHandle[2].text())) {479 if (isValidAreaCode(elementHandle[2],480 errorStatusHandle[2]) == true) {481 if (isValidPrefix(elementHandle[3],482 errorStatusHandle[2]) == true) {483 if (isValidPhone(elementHandle[4],484 errorStatusHandle[2])) {485 removeError(errorStatusHandle[2]);486 }487 }488 }489 490 }491 });492 elementHandle[5].on('blur', function() {493 if (isEmpty(elementHandle[5].val()))494 return;495 if (!isEmpty(errorStatusHandle[3].text())) {496 if (isValidAreaCode(elementHandle[5],497 errorStatusHandle[3]) == true) {498 if (isValidPrefix(elementHandle[6],499 errorStatusHandle[3]) == true) {500 if (isValidPhone(elementHandle[7],501 errorStatusHandle[3])) {502 removeError(errorStatusHandle[3]);503 }504 }505 }506 507 }508 });509 elementHandle[6].on('blur', function() {510 if (isEmpty(elementHandle[6].val()))511 return;512 if (!isEmpty(errorStatusHandle[3].text())) {513 if (isValidAreaCode(elementHandle[5],514 errorStatusHandle[3]) == true) {515 if (isValidPrefix(elementHandle[6],516 errorStatusHandle[3]) == true) {517 if (isValidPhone(elementHandle[7],518 errorStatusHandle[3])) {519 removeError(errorStatusHandle[3]);520 }521 }522 }523 524 }525 });526 elementHandle[7].on('blur', function() {527 if (isEmpty(elementHandle[7].val()))528 return;529 if (!isEmpty(errorStatusHandle[3].text())) {530 if (isValidAreaCode(elementHandle[5],531 errorStatusHandle[3]) == true) {532 if (isValidPrefix(elementHandle[6],533 errorStatusHandle[3]) == true) {534 if (isValidPhone(elementHandle[7],535 errorStatusHandle[3])) {536 removeError(errorStatusHandle[3]);537 }538 }539 }540 541 }542 });543 elementHandle[19].on('blur', function() {544 if (isEmpty(elementHandle[19].val()))545 return;546 if (!isEmpty(errorStatusHandle[15].text())) {547 if (isValidAreaCode(elementHandle[19],548 errorStatusHandle[15]) == true) {549 if (isValidPrefix(elementHandle[20],550 errorStatusHandle[15]) == true) {551 if (isValidPhone(elementHandle[21],552 errorStatusHandle[15])) {553 removeError(errorStatusHandle[15]);554 }555 }556 }557 }558 });559 elementHandle[20].on('blur', function() {560 if (isEmpty(elementHandle[20].val()))561 return;562 if (!isEmpty(errorStatusHandle[15].text())) {563 if (isValidAreaCode(elementHandle[19],564 errorStatusHandle[15]) == true) {565 if (isValidPrefix(elementHandle[20],566 errorStatusHandle[15]) == true) {567 if (isValidPhone(elementHandle[21],568 errorStatusHandle[15])) {569 removeError(errorStatusHandle[15]);570 }571 }572 }573 }574 });575 elementHandle[21].on('blur', function() {576 if (isEmpty(elementHandle[21].val()))577 return;578 if (!isEmpty(errorStatusHandle[15].text())) {579 if (isValidAreaCode(elementHandle[19],580 errorStatusHandle[15]) == true) {581 if (isValidPrefix(elementHandle[20],582 errorStatusHandle[15]) == true) {583 if (isValidPhone(elementHandle[21],584 errorStatusHandle[15])) {585 removeError(errorStatusHandle[15]);586 }587 }588 }589 }590 });591 // clear status when child first name is entered592 elementHandle[14].on('blur', function() {593 clearErrorStatus(elementHandle[14],594 errorStatusHandle[10]);595 });596 // clear status when child last name is entered597 elementHandle[15].on('blur', function() {598 clearErrorStatus(elementHandle[15],599 errorStatusHandle[11]);600 });601 elementHandle[12].on('blur', function() {602 if (isEmpty(elementHandle[12].val()))603 return;604 if (!isEmpty(errorStatusHandle[8].text())) {605 if (isValidZipcode(elementHandle[12],606 errorStatusHandle[8])) {607 removeError(errorStatusHandle[8]);608 }609 }610 });611 elementHandle[13].on('blur', function() {612 if (isEmpty(elementHandle[13].val()))613 return;614 if (!isEmpty(errorStatusHandle[9].text())) {615 if (isValidEmailAddress(elementHandle[13],616 errorStatusHandle[9])) {617 removeError(errorStatusHandle[9]);618 }619 }620 });621 // clear status when relationship is entered622 $('input[name=relationship]').click(function() {623 removeError(errorStatusHandle[4]);624 });625 // clear status when relationship is entered626 $('input[name=gender]').click(function() {627 removeError(errorStatusHandle[13]);628 });629 // clear status when address is entered630 elementHandle[9].on('blur',631 function() {632 clearErrorStatus(elementHandle[9],633 errorStatusHandle[5]);634 });635 // clear status when city is entered636 elementHandle[10].on('blur', function() {637 clearErrorStatus(elementHandle[10],638 errorStatusHandle[6]);639 });640 // clear status when photo is entered641 elementHandle[16].on('blur', function() {642 if (isEmpty(elementHandle[16].val()))643 return;644 if (!isEmpty(errorStatusHandle[12].text())) {645 if (isValidImage(elementHandle[16],646 errorStatusHandle[12])) {647 removeError(errorStatusHandle[12]);648 }649 }650 });651 elementHandle[11].on('blur', function() {652 if (isEmpty(elementHandle[11].val()))653 return;654 if (!isEmpty(errorStatusHandle[7].text())) {655 if (isValidState(elementHandle[11],656 errorStatusHandle[7])) {657 removeError(errorStatusHandle[7]);658 }659 }660 });661 // clear status when valid date is entered662 elementHandle[18].on('blur', function() {663 if (isEmpty(elementHandle[18].val()))664 return;665 if (!isEmpty(errorStatusHandle[14].text())) {666 if (isValidDate(elementHandle[18],667 errorStatusHandle[14])) {668 removeError(errorStatusHandle[14]);669 }670 }671 });672 // ///////////////////////////////////////////////////////////////673 elementHandle[11].on('keyup', function() {674 elementHandle[11].val(elementHandle[11].val()675 .toUpperCase());676 });677 // For phone number move the focus of the cursor ahead678 elementHandle[2].on('keyup', function() {679 if (elementHandle[2].val().length == 3)680 elementHandle[3].focus();681 });682 elementHandle[3].on('keyup', function() {683 if (elementHandle[3].val().length == 3)684 elementHandle[4].focus();685 });686 elementHandle[5].on('keyup', function() {687 if (elementHandle[5].val().length == 3)688 elementHandle[6].focus();689 });690 elementHandle[6].on('keyup', function() {691 if (elementHandle[6].val().length == 3)692 elementHandle[7].focus();693 });694 elementHandle[19].on('keyup', function() {695 if (elementHandle[19].val().length == 3)696 elementHandle[20].focus();697 });698 elementHandle[20].on('keyup', function() {699 if (elementHandle[20].val().length == 3)700 elementHandle[21].focus();701 });702 // //////////////////////////////////////////////////////////////////////////703 // Actions to be performed on button submit and reset704 $('form').on('submit', function(e){705 for (var i = 0; i <= 17; i++) {706 errorStatusHandle[i].text("");707 errorStatusHandle[i].removeClass("error");708 }709 if(isValidData()){710 var params = $('form').serialize();711 e.preventDefault(); 712 $.post('php/ajax_check_dups.php', params+'$photo='+$("#photo").val(), handleAnswer);713 714 715 }else{716 return false;717 }718 719 720 });721 722 function handleAnswer(answer){723 724 if($.trim(answer) == "OK") {725 send_file();726 727 }728 else if ($.trim(answer) == "DUP"){729 $('#status').html("Duplicate! Same child cannot be enrolled again");730 $('#status').css('color','red');731 }732 else{733 $('#status').html("Database error"); 734 $('#status').css('color','red'); 735 } 736 }737 738 function handleAjaxPost(answer) {739 740 if($.trim(answer) == "confirmation success") {741 var params = $('form').serialize();742 $.post('php/confirmation.php', params+'&photo='+$("#photo").val(), confirmHandler);743 // window.location.assign("http://jadran.sdsu.edu/~jadrn046/proj2-b/php/confirmation.php");744 }else{745 $('#status').html(answer);746 $('#status').css('color','red');747 748 } 749 }750 751 function confirmHandler(response){752 $('body').html(response);753 } 754 755 function send_file() { 756 757 var form_data = new FormData($('form')[0]); 758 759 form_data.append("image", document.getElementById("photo").files[0]);760 $.ajax( {761 url: "php/ajax_file_upload.php",762 type: "post",763 data: form_data,764 processData: false,765 contentType: false,766 success: function(response) {767 768 if ($.trim(response) == "SUCCESS"){769 var params = $('form').serialize();770 $.post('php/processRequest.php', params+'&photo='+$("#photo").val(),handleAjaxPost);771 772 } else if($.trim(response) == "DUPLICATE") {773 $('#status').html("Error, the file already exists on the server");774 $('#status').css('color','red');775 776 } else if ($.trim(response) == "LARGE"){777 $('#status').html("The file was too big to upload, the limit is 2MB");778 $('#status').css('color','red');779 }780 781 // var toDisplay = "<img src=\"/~jadrn046/proj2-b/_myImages_/" + fname + "\" />"; 782 // var toDisplay = "<img src=\"/~jadrn046/proj2-b/_myImages_/beaches_panoramic7.jpg\" />"; 783 784 },785 error: function(response) {786 787 $('#status').html("Sorry, upload error "+response.statusText); 788 $('#status').css('color','red'); 789 }790 });791 }792 $(':reset').on('click', function() {793 for (var i = 0; i <= 17; i++) {794 errorStatusHandle[i].text("");795 errorStatusHandle[i].removeClass("error");796 }797 });...

Full Screen

Full Screen

validation.txt.js

Source:validation.txt.js Github

copy

Full Screen

1/* Shubha Ravikumar, FNU Account: jadrn0462CS545, Fall 20143Project #2 */4function isEmpty(fieldValue) {5 return $.trim(fieldValue).length == 0;6}7function isValidStateAbbr(state) {8 var stateList = new Array("AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC",9 "DC2", "DE", "FL", "GA", "GU", "HI", "IA", "ID", "IL", "IN", "KS",10 "KY", "LA", "MA", "MD", "ME", "MH", "MI", "MN", "MO", "MS", "MT",11 "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR",12 "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA",13 "WI", "WV", "WY");14 for (var i = 0; i < stateList.length; i++)15 if (stateList[i] == $.trim(state.toUpperCase()))16 return true;17 return false;18}19function isValidEmail(emailAddress) {20 var pattern = new RegExp(21 /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);22 return pattern.test(emailAddress);23}24$(document)25 .ready(26 function() {27 var elementHandle = new Array(28);28 var errorStatusHandle = new Array(28);29 // Handlers to access elements :-30 // Parent basic Info handlers31 elementHandle[0] = $('[name="parentFirstName"]');32 elementHandle[1] = $('[name="parentLastName"]');33 elementHandle[2] = $('[name="pmArea"]');34 elementHandle[3] = $('[name="pmPrefix"]');35 elementHandle[4] = $('[name="pmPhone"]');36 elementHandle[5] = $('[name="phArea"]');37 elementHandle[6] = $('[name="phPrefix"]');38 elementHandle[7] = $('[name="phPhone"]');39 // Parent additional info handlers40 elementHandle[8] = $('input[name=relationship]:checked');41 elementHandle[9] = $('[name="addressLine1"]');42 elementHandle[10] = $('[name="city"]');43 elementHandle[11] = $('[name="state"]');44 elementHandle[12] = $('[name="postcode"]');45 elementHandle[13] = $('[name="email"]');46 // Child info handlers47 elementHandle[14] = $('[name="childFirstName"]');48 elementHandle[15] = $('[name="childLastName"]');49 elementHandle[16] = $('[name="photo"]');50 elementHandle[17] = $('[name="gender"]');51 elementHandle[18] = $('[name="dob"]');52 // Child additional info handlers53 elementHandle[19] = $('[name="scArea"]');54 elementHandle[20] = $('[name="scPrefix"]');55 elementHandle[21] = $('[name="scPhone"]');56 elementHandle[22] = $('[name="childNickName"]');57 elementHandle[23] = $('[name="secondaryContactName"]');58 // Error Status59 // Parent basic Info error status60 errorStatusHandle[0] = $('#parentFirstNameErrMsg');61 errorStatusHandle[1] = $('#parentLastNameErrMsg');62 errorStatusHandle[2] = $('#cellPhoneErr');63 errorStatusHandle[3] = $('#telPhoneErr');64 // Parent additional info error status65 errorStatusHandle[4] = $('#relationshipErrMsg');66 errorStatusHandle[5] = $('#addressErrMsg');67 errorStatusHandle[6] = $('#cityErrMsg');68 errorStatusHandle[7] = $('#stateErrMsg');69 errorStatusHandle[8] = $('#postCodeErrMsg');70 errorStatusHandle[9] = $('#emailErrMsg');71 // Child info error status72 errorStatusHandle[10] = $('#childFirstNameErrMsg');73 errorStatusHandle[11] = $('#childLastNameErrMsg');74 errorStatusHandle[12] = $('#imgFormatErrMsg');75 errorStatusHandle[13] = $('#genderErrMsg');76 errorStatusHandle[14] = $('#dateErrMsg');77 // Child additional info error status78 errorStatusHandle[15] = $('#scTelPhoneErrMsg');79 errorStatusHandle[16] = $('#nicknameErrMsg');80 errorStatusHandle[17] = $('#scNameErrMsg');81 function setErrorStatus(elementHandler, errorStatusHandle,82 msg) {83 errorStatusHandle.addClass("error");84 errorStatusHandle.text(msg);85 elementHandler.focus();86 }87 function validateNonEmptyField(elementHandler,88 errorStatusHandle, msg) {89 if (isEmpty(elementHandler.val())) {90 setErrorStatus(elementHandler, errorStatusHandle,91 msg);92 return false;93 }94 return true;95 }96 function isValidName() {97 var isValid = true;98 if (validateNonEmptyField(elementHandle[23],99 errorStatusHandle[17],100 "Please enter the name") == false) {101 isValid = false;102 }103 if (validateNonEmptyField(elementHandle[22],104 errorStatusHandle[16],105 "Please enter the nickname") == false) {106 isValid = false;107 }108 if (validateNonEmptyField(elementHandle[15],109 errorStatusHandle[11],110 "Please enter the last name") == false) {111 isValid = false;112 }113 if (validateNonEmptyField(elementHandle[14],114 errorStatusHandle[10],115 "Please enter the first name") == false) {116 isValid = false;117 }118 if (validateNonEmptyField(elementHandle[1],119 errorStatusHandle[1],120 "Please enter the last name") == false) {121 isValid = false;122 }123 if (validateNonEmptyField(elementHandle[0],124 errorStatusHandle[0],125 "Please enter the first name") == false) {126 isValid = false;127 }128 return isValid;129 }130 function isValidAreaCode(elementHandler, errorStatusHandle) {131 if (isEmpty(elementHandler.val())) {132 setErrorStatus(elementHandler, errorStatusHandle,133 "Please enter the area code");134 return false;135 }136 if (!$.isNumeric(elementHandler.val())) {137 setErrorStatus(elementHandler, errorStatusHandle,138 "The area code is invalid, numbers only");139 return false;140 }141 if (elementHandler.val().length != 3) {142 setErrorStatus(elementHandler, errorStatusHandle,143 "The area code must have three digits");144 return false;145 }146 return true;147 }148 function isValidPrefix(elementHandler, errorStatusHandle) {149 if (isEmpty(elementHandler.val())) {150 setErrorStatus(elementHandler, errorStatusHandle,151 "Please enter the phone number prefix");152 return false;153 }154 if (!$.isNumeric(elementHandler.val())) {155 setErrorStatus(elementHandler, errorStatusHandle,156 "The prefix is invalid, numbers only");157 return false;158 }159 if (elementHandler.val().length != 3) {160 setErrorStatus(elementHandler, errorStatusHandle,161 "The prefix must have three digits");162 return false;163 }164 return true;165 }166 function isValidPhone(elementHandler, errorStatusHandle) {167 if (isEmpty(elementHandler.val())) {168 setErrorStatus(elementHandler, errorStatusHandle,169 "Please enter the phone number");170 return false;171 }172 if (!$.isNumeric(elementHandler.val())) {173 setErrorStatus(elementHandler, errorStatusHandle,174 "The phone code is invalid, numbers only");175 return false;176 }177 if (elementHandler.val().length != 4) {178 setErrorStatus(elementHandler, errorStatusHandle,179 "The phone code must have four digits");180 return false;181 }182 return true;183 }184 function isvalidPhoneNumber() {185 var isValid = true;186 var isValidSContactNumber = false;187 if (isValidAreaCode(elementHandle[19],188 errorStatusHandle[15]) == true) {189 if (isValidPrefix(elementHandle[20],190 errorStatusHandle[15]) == true) {191 if (isValidPhone(elementHandle[21],192 errorStatusHandle[15]) == true) {193 isValidSContactNumber = true;194 }195 }196 }197 198 if (isValidSContactNumber == false) {199 isValid = false;200 }201 var isValidCellNumber = false;202 if (isValidAreaCode(elementHandle[2],203 errorStatusHandle[2]) == true) {204 if (isValidPrefix(elementHandle[3],205 errorStatusHandle[2]) == true) {206 if (isValidPhone(elementHandle[4],207 errorStatusHandle[2]) == true) {208 isValidCellNumber = true;209 }210 }211 }212 if (isValidCellNumber == false) {213 isValid = false;214 }215 var isValidTelNumber = false;216 if (isEmpty(elementHandle[5].val())217 && isEmpty(elementHandle[6].val())218 && isEmpty(elementHandle[7].val())) {219 isValidTelNumber = true;220 } else {221 if (isValidAreaCode(elementHandle[5],222 errorStatusHandle[3]) == true) {223 if (isValidPrefix(elementHandle[6],224 errorStatusHandle[3]) == true) {225 if (isValidPhone(elementHandle[7],226 errorStatusHandle[3]) == true) {227 isValidTelNumber = true;228 }229 }230 }}231 if (isValidTelNumber == false) {232 isValid = false;233 }234 return isValid;235 }236 function isValidEmailAddress(elementHandler,237 errorStatusHandler) {238 if (isEmpty(elementHandler.val())) {239 setErrorStatus(elementHandler, errorStatusHandler,240 "Please enter your email address");241 return false;242 }243 if (!isValidEmail(elementHandler.val())) {244 setErrorStatus(elementHandler, errorStatusHandler,245 "The email address appears to be invalid");246 return false;247 }248 return true;249 }250 function isValidState(elementHandler, errorStatusHandler) {251 if (isEmpty(elementHandler.val())) {252 setErrorStatus(elementHandler, errorStatusHandler,253 "Please enter your state");254 return false;255 }256 if (!isValidStateAbbr(elementHandler.val())) {257 setErrorStatus(elementHandler, errorStatusHandler,258 "Invalid state, please use the two letter state abbreviation");259 return false;260 }261 return true;262 }263 function isValidZipcode(elementHandler, errorStatusHandler) {264 if (isEmpty(elementHandler.val())) {265 setErrorStatus(elementHandler, errorStatusHandler,266 "Please enter your zip code");267 return false;268 }269 if (!$.isNumeric(elementHandler.val())) {270 setErrorStatus(elementHandler, errorStatusHandler,271 "Invalid zip code, numbers only please");272 return false;273 }274 if (elementHandler.val().length != 5) {275 setErrorStatus(elementHandler, errorStatusHandler,276 "The zip code must have five digits");277 return false;278 }279 return true;280 }281 function isValidImage(elementHandler, errorStatusHandler) {282 if (isEmpty(elementHandler.val())) {283 setErrorStatus(elementHandler, errorStatusHandler,284 "Please upload a photo in .jpg or .png format");285 return false;286 }287 288 if (elementHandler.val().length > 15) {289 setErrorStatus(elementHandler, errorStatusHandler,290 "File name cannot be more than 15 characters");291 return false;292 }293 var fileExtension = elementHandler.val().substr(294 elementHandler.val().length - 4).toLowerCase();295 if (!(fileExtension == ".jpg" || fileExtension == ".png")) {296 setErrorStatus(elementHandler, errorStatusHandler,297 "Please upload a photo in .jpg or .png format only");298 return false;299 }300 return true;301 }302 function isValidDate(elementHandler, errorStatusHandler) {303 if (isEmpty(elementHandler.val())) {304 setErrorStatus(elementHandler, errorStatusHandler,305 "Please enter date in mm/dd/yyyy format");306 return false;307 }308 // Declare Regex , Checks for dd/mm/yyyy format.309 var dateRegEx = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;310 if (!dateRegEx.test(elementHandler.val())) {311 setErrorStatus(elementHandler, errorStatusHandler,312 "Invalid date format. Enter in mm/dd/yyyy format");313 return false;314 }315 var dateParts = elementHandler.val().split("/");316 // now turn the three values into a Date object and317 // check them318 var dob = new Date(dateParts[2], dateParts[0] - 1,319 dateParts[1]);320 var checkDay = dob.getDate();321 var checkMonth = dob.getMonth() + 1;322 var checkYear = dob.getFullYear();323 if (!(dateParts[1] == checkDay324 && dateParts[0] == checkMonth && dateParts[2] == checkYear)) {325 setErrorStatus(elementHandler, errorStatusHandler,326 "Please enter a valid date");327 return false;328 }329 var endDate = new Date(2014, 5, 2);330 var diff = endDate.getTime() - dob.getTime();331 var yrs = Math.floor(diff332 / (1000 * 60 * 60 * 24 * 365.25));333 if (!(yrs >= 12 && yrs <= 18)) {334 setErrorStatus(elementHandler, errorStatusHandler,335 "Only children of age 12 to 18 are allowed");336 return false;337 }338 return true;339 }340 function isValidData() {341 var isValid = true;342 var selectedRelationship = $(343 'input[name=relationship]:checked').val();344 if (isEmpty(selectedRelationship)) {345 setErrorStatus(elementHandle[8],346 errorStatusHandle[4],347 "Please enter relationship");348 isValid = false;349 }350 var selectedGender = $('input[name=gender]:checked')351 .val();352 if (isEmpty(selectedGender)) {353 setErrorStatus(elementHandle[17],354 errorStatusHandle[13],355 "Please enter gender");356 isValid = false;357 }358 if (isValidDate(elementHandle[18],359 errorStatusHandle[14]) == false) {360 isValid = false;361 }362 if (isValidImage(elementHandle[16],363 errorStatusHandle[12]) == false) {364 isValid = false;365 }366 if (isValidZipcode(elementHandle[12],367 errorStatusHandle[8]) == false) {368 isValid = false;369 }370 if (isValidState(elementHandle[11],371 errorStatusHandle[7]) == false) {372 isValid = false;373 }374 if (isEmpty(elementHandle[10].val())) {375 setErrorStatus(elementHandle[10],376 errorStatusHandle[6],377 "Please enter your city");378 isValid = false;379 }380 if (isEmpty(elementHandle[9].val())) {381 setErrorStatus(elementHandle[9],382 errorStatusHandle[5],383 "Please enter your address");384 isValid = false;385 }386 if (isValidEmailAddress(elementHandle[13],387 errorStatusHandle[9]) == false) {388 isValid = false;389 }390 if (isvalidPhoneNumber() == false) {391 isValid = false;392 }393 if (isValidName() == false) {394 isValid = false;395 }396 return isValid;397 }398 // focus on 1st field on page load399 elementHandle[0].focus();400 // HANDLERS401 // on blur, if the user has entered valid data, the error402 // message should no longer show.403 function clearErrorStatus(elementHandler, errorStatusHandle) {404 if (isEmpty(elementHandler.val()))405 return;406 removeError(errorStatusHandle);407 }408 function removeError(errorStatusHandle) {409 errorStatusHandle.text("");410 errorStatusHandle.removeClass("error");411 }412 // clear status when parent first name is entered413 elementHandle[0].on('blur',414 function() {415 clearErrorStatus(elementHandle[0],416 errorStatusHandle[0]);417 });418 // clear status when parent last is entered419 elementHandle[1].on('blur',420 function() {421 clearErrorStatus(elementHandle[1],422 errorStatusHandle[1]);423 });424 // clear status when parent first name is entered425 elementHandle[22].on('blur',426 function() {427 clearErrorStatus(elementHandle[22],428 errorStatusHandle[16]);429 });430 431 // clear status when parent first name is entered432 elementHandle[23].on('blur',433 function() {434 clearErrorStatus(elementHandle[23],435 errorStatusHandle[17]);436 });437 elementHandle[2].on('blur', function() {438 if (isEmpty(elementHandle[2].val()))439 return;440 if (!isEmpty(errorStatusHandle[2].text())) {441 if (isValidAreaCode(elementHandle[2],442 errorStatusHandle[2]) == true) {443 if (isValidPrefix(elementHandle[3],444 errorStatusHandle[2]) == true) {445 if (isValidPhone(elementHandle[4],446 errorStatusHandle[2])) {447 removeError(errorStatusHandle[2]);448 }449 }450 }451 /*452 * if (isValidAreaCode(elementHandle[2],453 * errorStatusHandle[2])) {454 * removeError(errorStatusHandle[2]); }455 */456 }457 });458 elementHandle[3].on('blur', function() {459 if (isEmpty(elementHandle[3].val()))460 return;461 if (!isEmpty(errorStatusHandle[2].text())) {462 if (isValidAreaCode(elementHandle[2],463 errorStatusHandle[2]) == true) {464 if (isValidPrefix(elementHandle[3],465 errorStatusHandle[2]) == true) {466 if (isValidPhone(elementHandle[4],467 errorStatusHandle[2])) {468 removeError(errorStatusHandle[2]);469 }470 }471 }472 473 }474 });475 elementHandle[4].on('blur', function() {476 if (isEmpty(elementHandle[4].val()))477 return;478 if (!isEmpty(errorStatusHandle[2].text())) {479 if (isValidAreaCode(elementHandle[2],480 errorStatusHandle[2]) == true) {481 if (isValidPrefix(elementHandle[3],482 errorStatusHandle[2]) == true) {483 if (isValidPhone(elementHandle[4],484 errorStatusHandle[2])) {485 removeError(errorStatusHandle[2]);486 }487 }488 }489 490 }491 });492 elementHandle[5].on('blur', function() {493 if (isEmpty(elementHandle[5].val()))494 return;495 if (!isEmpty(errorStatusHandle[3].text())) {496 if (isValidAreaCode(elementHandle[5],497 errorStatusHandle[3]) == true) {498 if (isValidPrefix(elementHandle[6],499 errorStatusHandle[3]) == true) {500 if (isValidPhone(elementHandle[7],501 errorStatusHandle[3])) {502 removeError(errorStatusHandle[3]);503 }504 }505 }506 507 }508 });509 elementHandle[6].on('blur', function() {510 if (isEmpty(elementHandle[6].val()))511 return;512 if (!isEmpty(errorStatusHandle[3].text())) {513 if (isValidAreaCode(elementHandle[5],514 errorStatusHandle[3]) == true) {515 if (isValidPrefix(elementHandle[6],516 errorStatusHandle[3]) == true) {517 if (isValidPhone(elementHandle[7],518 errorStatusHandle[3])) {519 removeError(errorStatusHandle[3]);520 }521 }522 }523 524 }525 });526 elementHandle[7].on('blur', function() {527 if (isEmpty(elementHandle[7].val()))528 return;529 if (!isEmpty(errorStatusHandle[3].text())) {530 if (isValidAreaCode(elementHandle[5],531 errorStatusHandle[3]) == true) {532 if (isValidPrefix(elementHandle[6],533 errorStatusHandle[3]) == true) {534 if (isValidPhone(elementHandle[7],535 errorStatusHandle[3])) {536 removeError(errorStatusHandle[3]);537 }538 }539 }540 541 }542 });543 elementHandle[19].on('blur', function() {544 if (isEmpty(elementHandle[19].val()))545 return;546 if (!isEmpty(errorStatusHandle[15].text())) {547 if (isValidAreaCode(elementHandle[19],548 errorStatusHandle[15]) == true) {549 if (isValidPrefix(elementHandle[20],550 errorStatusHandle[15]) == true) {551 if (isValidPhone(elementHandle[21],552 errorStatusHandle[15])) {553 removeError(errorStatusHandle[15]);554 }555 }556 }557 }558 });559 elementHandle[20].on('blur', function() {560 if (isEmpty(elementHandle[20].val()))561 return;562 if (!isEmpty(errorStatusHandle[15].text())) {563 if (isValidAreaCode(elementHandle[19],564 errorStatusHandle[15]) == true) {565 if (isValidPrefix(elementHandle[20],566 errorStatusHandle[15]) == true) {567 if (isValidPhone(elementHandle[21],568 errorStatusHandle[15])) {569 removeError(errorStatusHandle[15]);570 }571 }572 }573 }574 });575 elementHandle[21].on('blur', function() {576 if (isEmpty(elementHandle[21].val()))577 return;578 if (!isEmpty(errorStatusHandle[15].text())) {579 if (isValidAreaCode(elementHandle[19],580 errorStatusHandle[15]) == true) {581 if (isValidPrefix(elementHandle[20],582 errorStatusHandle[15]) == true) {583 if (isValidPhone(elementHandle[21],584 errorStatusHandle[15])) {585 removeError(errorStatusHandle[15]);586 }587 }588 }589 }590 });591 // clear status when child first name is entered592 elementHandle[14].on('blur', function() {593 clearErrorStatus(elementHandle[14],594 errorStatusHandle[10]);595 });596 // clear status when child last name is entered597 elementHandle[15].on('blur', function() {598 clearErrorStatus(elementHandle[15],599 errorStatusHandle[11]);600 });601 elementHandle[12].on('blur', function() {602 if (isEmpty(elementHandle[12].val()))603 return;604 if (!isEmpty(errorStatusHandle[8].text())) {605 if (isValidZipcode(elementHandle[12],606 errorStatusHandle[8])) {607 removeError(errorStatusHandle[8]);608 }609 }610 });611 elementHandle[13].on('blur', function() {612 if (isEmpty(elementHandle[13].val()))613 return;614 if (!isEmpty(errorStatusHandle[9].text())) {615 if (isValidEmailAddress(elementHandle[13],616 errorStatusHandle[9])) {617 removeError(errorStatusHandle[9]);618 }619 }620 });621 // clear status when relationship is entered622 $('input[name=relationship]').click(function() {623 removeError(errorStatusHandle[4]);624 });625 // clear status when relationship is entered626 $('input[name=gender]').click(function() {627 removeError(errorStatusHandle[13]);628 });629 // clear status when address is entered630 elementHandle[9].on('blur',631 function() {632 clearErrorStatus(elementHandle[9],633 errorStatusHandle[5]);634 });635 // clear status when city is entered636 elementHandle[10].on('blur', function() {637 clearErrorStatus(elementHandle[10],638 errorStatusHandle[6]);639 });640 // clear status when photo is entered641 elementHandle[16].on('blur', function() {642 if (isEmpty(elementHandle[16].val()))643 return;644 if (!isEmpty(errorStatusHandle[12].text())) {645 if (isValidImage(elementHandle[16],646 errorStatusHandle[12])) {647 removeError(errorStatusHandle[12]);648 }649 }650 });651 elementHandle[11].on('blur', function() {652 if (isEmpty(elementHandle[11].val()))653 return;654 if (!isEmpty(errorStatusHandle[7].text())) {655 if (isValidState(elementHandle[11],656 errorStatusHandle[7])) {657 removeError(errorStatusHandle[7]);658 }659 }660 });661 // clear status when valid date is entered662 elementHandle[18].on('blur', function() {663 if (isEmpty(elementHandle[18].val()))664 return;665 if (!isEmpty(errorStatusHandle[14].text())) {666 if (isValidDate(elementHandle[18],667 errorStatusHandle[14])) {668 removeError(errorStatusHandle[14]);669 }670 }671 });672 // ///////////////////////////////////////////////////////////////673 elementHandle[11].on('keyup', function() {674 elementHandle[11].val(elementHandle[11].val()675 .toUpperCase());676 });677 // For phone number move the focus of the cursor ahead678 elementHandle[2].on('keyup', function() {679 if (elementHandle[2].val().length == 3)680 elementHandle[3].focus();681 });682 elementHandle[3].on('keyup', function() {683 if (elementHandle[3].val().length == 3)684 elementHandle[4].focus();685 });686 elementHandle[5].on('keyup', function() {687 if (elementHandle[5].val().length == 3)688 elementHandle[6].focus();689 });690 elementHandle[6].on('keyup', function() {691 if (elementHandle[6].val().length == 3)692 elementHandle[7].focus();693 });694 elementHandle[19].on('keyup', function() {695 if (elementHandle[19].val().length == 3)696 elementHandle[20].focus();697 });698 elementHandle[20].on('keyup', function() {699 if (elementHandle[20].val().length == 3)700 elementHandle[21].focus();701 });702 // //////////////////////////////////////////////////////////////////////////703 // Actions to be performed on button submit and reset704 $('form').on('submit', function(e){705 for (var i = 0; i <= 17; i++) {706 errorStatusHandle[i].text("");707 errorStatusHandle[i].removeClass("error");708 }709 if(isValidData()){710 var params = $('form').serialize();711 e.preventDefault(); 712 $.post('php/ajax_check_dups.php', params+'$photo='+$("#photo").val(), handleAnswer);713 714 715 }else{716 return false;717 }718 719 720 });721 722 function handleAnswer(answer){723 724 if($.trim(answer) == "OK") {725 send_file();726 727 }728 else if ($.trim(answer) == "DUP"){729 $('#status').html("Duplicate! Same child cannot be enrolled again");730 $('#status').css('color','red');731 }732 else{733 $('#status').html("Database error"); 734 $('#status').css('color','red'); 735 } 736 }737 738 function handleAjaxPost(answer) {739 740 if($.trim(answer) == "confirmation success") {741 var params = $('form').serialize();742 $.post('php/confirmation.php', params+'&photo='+$("#photo").val(), confirmHandler);743 // window.location.assign("http://jadran.sdsu.edu/~jadrn046/proj2-b/php/confirmation.php");744 }else{745 $('#status').html(answer);746 $('#status').css('color','red');747 748 } 749 }750 751 function confirmHandler(response){752 $('body').html(response);753 } 754 755 function send_file() { 756 757 var form_data = new FormData($('form')[0]); 758 759 form_data.append("image", document.getElementById("photo").files[0]);760 $.ajax( {761 url: "php/ajax_file_upload.php",762 type: "post",763 data: form_data,764 processData: false,765 contentType: false,766 success: function(response) {767 768 if ($.trim(response) == "SUCCESS"){769 var params = $('form').serialize();770 $.post('php/processRequest.php', params+'&photo='+$("#photo").val(),handleAjaxPost);771 772 } else if($.trim(response) == "DUPLICATE") {773 $('#status').html("Error, the file already exists on the server");774 $('#status').css('color','red');775 776 } else if ($.trim(response) == "LARGE"){777 $('#status').html("The file was too big to upload, the limit is 2MB");778 $('#status').css('color','red');779 }780 781 // var toDisplay = "<img src=\"/~jadrn046/proj2-b/_myImages_/" + fname + "\" />"; 782 // var toDisplay = "<img src=\"/~jadrn046/proj2-b/_myImages_/beaches_panoramic7.jpg\" />"; 783 784 },785 error: function(response) {786 787 $('#status').html("Sorry, upload error "+response.statusText); 788 $('#status').css('color','red'); 789 }790 });791 }792 $(':reset').on('click', function() {793 for (var i = 0; i <= 17; i++) {794 errorStatusHandle[i].text("");795 errorStatusHandle[i].removeClass("error");796 }797 });...

Full Screen

Full Screen

ElementHandler.spec.ts

Source:ElementHandler.spec.ts Github

copy

Full Screen

1import { ElementHandler } from '../ElementHandler';2describe('ElementHandler', () => {3 it('should have set the correct element', () => {4 const newElement = document.createElement('div');5 const elementHandler = new ElementHandler(newElement);6 expect(elementHandler.element).toEqual(newElement);7 });8 it('It should correctly set the value of a DOM element - number', () => {9 const newElement = document.createElement('div');10 const elementHandler = new ElementHandler(newElement);11 elementHandler.set(5);12 expect(newElement.innerHTML).toBe('5');13 });14 it('It should correctly set the value of a DOM element - string', () => {15 const newElement = document.createElement('div');16 const elementHandler = new ElementHandler(newElement);17 const DEFAULT_TEXT = 'myText';18 elementHandler.set(DEFAULT_TEXT);19 expect(newElement.innerHTML).toBe(DEFAULT_TEXT);20 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { elementHandler } = require('storybook-test-runner');2const { expect } = require('chai');3describe('test elementHandler', () => {4 it('should render the component', () => {5 const component = elementHandler('my-component');6 expect(component).to.be.ok;7 });8});9import { configure, addDecorator } from '@storybook/html';10import { withKnobs } from '@storybook/addon-knobs';11import { withTests } from 'storybook-addon-jest';12import results from '../.jest-test-results.json';13addDecorator(withKnobs);14addDecorator(withTests({ results }));15configure(require.context('../src', true, /\.stories\.js$/), module);16{17 "snapshot": {18 },19 {20 {21 }

Full Screen

Using AI Code Generation

copy

Full Screen

1import { elementHandler } from 'storybook-test-runner';2describe('my-element', () => {3 it('should render', async () => {4 const element = await elementHandler('my-element');5 expect(element).toBeTruthy();6 });7});8import { storyHandler } from 'storybook-test-runner';9describe('my-element', () => {10 it('should render', async () => {11 const element = await storyHandler('my-element');12 expect(element).toBeTruthy();13 });14});15import { storyHandler } from 'storybook-test-runner';16describe('my-element', () => {17 it('should render', async () => {18 const element = await storyHandler('my-element', 'story2');19 expect(element).toBeTruthy();20 });21});22import { storyHandler } from 'storybook-test-runner';23describe('my-element', () => {24 it('should render', async () => {25 const element = await storyHandler('my-element', 'story2', 'my-element2');26 expect(element).toBeTruthy();27 });28});29import { storyHandler } from 'storybook-test-runner';30describe('my-element', () => {31 it('should render', async () => {32 const element = await storyHandler('my-element', 'story2', 'my-element2', 'story3');33 expect(element).toBeTruthy();34 });35});36import { storyHandler } from 'storybook-test-runner';37describe('my-element', () => {38 it('should render', async () => {39 const element = await storyHandler('my-element', 'story2', 'my-element2', 'story3', '

Full Screen

Using AI Code Generation

copy

Full Screen

1const { elementHandler } = require('storybook-test-runner');2const { By } = require('selenium-webdriver');3describe('My First Storybook', () => {4 it('should render the button', async () => {5 const button = await storybook('Button');6 const text = await button.findElement(By.css('button')).getText();7 expect(text).toEqual('Hello World!');8 });9});10{11 "scripts": {12 }13}14 ✓ should render the button (19ms)

Full Screen

Using AI Code Generation

copy

Full Screen

1import {elementHandler} from 'storybook-test-runner';2import MyComponent from './MyComponent';3elementHandler('MyComponent', MyComponent);4import React from 'react';5const MyComponent = () => {6}7export default MyComponent;8import React from 'react';9import { storiesOf } from '@storybook/react';10import MyComponent from './MyComponent';11storiesOf('MyComponent', module)12 .add('default', () => <MyComponent />);13import React from 'react';14import { shallow } from 'enzyme';15import MyComponent from './MyComponent';16describe('MyComponent', () => {17 it('should render', () => {18 const wrapper = shallow(<MyComponent />);19 expect(wrapper).toMatchSnapshot();20 });21});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { elementHandler } = require('storybook-test-runner');2it('should render button', async () => {3 const button = await elementHandler('button');4 await expect(button).toBeVisible();5});6it('should render input', async () => {7 const input = await elementHandler('input');8 await expect(input).toBeVisible();9});10it('should render checkbox', async () => {11 const checkbox = await elementHandler('input[type="checkbox"]');12 await expect(checkbox).toBeVisible();13});14it('should render radio button', async () => {15 const radio = await elementHandler('input[type="radio"]');16 await expect(radio).toBeVisible();17});18it('should render select box', async () => {19 const select = await elementHandler('select');20 await expect(select).toBeVisible();21});22it('should render textarea', async () => {23 const textarea = await elementHandler('textarea');24 await expect(textarea).toBeVisible();25});26it('should render link', async () => {27 const link = await elementHandler('a');28 await expect(link).toBeVisible();29});30it('should render image', async () => {31 const image = await elementHandler('img');32 await expect(image).toBeVisible();33});34it('should render video', async () => {35 const video = await elementHandler('video');36 await expect(video).toBeVisible();37});38it('should render audio', async () => {39 const audio = await elementHandler('audio');40 await expect(audio).toBeVisible();41});42it('should render svg', async () => {43 const svg = await elementHandler('svg');44 await expect(svg).toBeVisible();45});46it('should render table', async () => {47 const table = await elementHandler('table');48 await expect(table).toBeVisible();49});50it('should render list', async () => {51 const list = await elementHandler('ul');52 await expect(list).toBeVisible();53});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { elementHandler } = require('storybook-test-runner');2const { click } = require('storybook-test-runner');3const element = elementHandler('button');4if (element.isPresent()) {5 click(element);6}7const { elementHandler } = require('storybook-test-runner');8const { click } = require('storybook-test-runner');9const element = elementHandler('button');10if (element.isPresent()) {11 click(element);12}13const { elementHandler } = require('storybook-test-runner');14const { click } = require('storybook-test-runner');15const element = elementHandler('button');16if (element.isPresent()) {17 click(element);18}19const { elementHandler } = require('storybook-test-runner');20const { click } = require('storybook-test-runner');21const element = elementHandler('button');22if (element.isPresent()) {23 click(element);24}25const { elementHandler } = require('storybook-test-runner');26const { click } = require('storybook-test-runner');27const element = elementHandler('button');28if (element.isPresent()) {29 click(element);30}31const { elementHandler } = require('

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-test-runner automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful