From 4346074dd0e01277fc48748301f0a1d4caa77238 Mon Sep 17 00:00:00 2001 From: Erin Smith Date: Wed, 3 Jun 2015 14:01:14 -0400 Subject: [PATCH 1/3] Working solution ripe for refactor --- node_modules/.DS_Store | Bin 0 -> 6148 bytes validator.js | 74 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 node_modules/.DS_Store diff --git a/node_modules/.DS_Store b/node_modules/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..19a9def92aa7ec648171e6b9bf907becea861c75 GIT binary patch literal 6148 zcmeHKOG*P#5UkcL0usp5JP#&apA&^R6}>Y z*VFYLQ;X?o0Jb_k-U3SibGjowJWS1>yHD(*GDf8HjC<_xf_FUOW>S4V;oJp!>~X;B zi2r~ij&IvTzuWiEdBgc5l$8QfKnh3!DIf)Yp@8>Z+Waa}Q3^-_De$d;e;*p%u`3)B zOzY%~lhN#qB)5 zMLDcXRFnczV64DpZkOKwH}oIo|1n8BDIf*@l># Date: Wed, 3 Jun 2015 14:38:07 -0400 Subject: [PATCH 2/3] Fail attempts to refactor and revert back to original solution --- validator.js | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/validator.js b/validator.js index 6de8a8a..b4c69ef 100644 --- a/validator.js +++ b/validator.js @@ -1,7 +1,7 @@ // $() is an alias for $(document).ready() when you pass it a function $(document).ready( function() { - $("ul").children().hide(); + $(".errors").children().hide(); $("form").submit( function() { ValidateForm(); @@ -25,10 +25,10 @@ $(document).ready( function() { if (invalid_format) { PreventSubmission; - $("ul li:nth-child(1)").show(); + $(".errors li:nth-child(1)").show(); } else { - $("ul li:nth-child(1)").hide(); + $(".errors li:nth-child(1)").hide(); }; }; @@ -41,33 +41,29 @@ $(document).ready( function() { var no_capital_chars = !capital_regex.test(password) var no_numbers = !num_regex.test(password) - if (too_short) { PreventSubmission; - $("ul li:nth-child(2)").show(); + $(".errors li:nth-child(2)").show(); } else { - $("ul li:nth-child(2)").hide(); + $(".errors li:nth-child(2)").hide(); }; + if (no_capital_chars) { PreventSubmission; - $("ul li:nth-child(3)").show(); + $(".errors li:nth-child(3)").show(); } else { - $("ul li:nth-child(3)").hide(); + $(".errors li:nth-child(3)").hide(); }; if (no_numbers) { PreventSubmission; - $("ul li:nth-child(4)").show(); + $(".errors li:nth-child(4)").show(); } else { - $("ul li:nth-child(4)").hide(); + $(".errors li:nth-child(4)").hide(); }; }; -}); - -// Are these functions queries or commands? Which shoould they be? - -// Ask about addclass? Would it have made more sense to add classes to the li's? \ No newline at end of file +}); \ No newline at end of file From d2f8d0b58d6c8bcbca9f3a925a8fe9120fd0514f Mon Sep 17 00:00:00 2001 From: Erin Smith Date: Thu, 4 Jun 2015 10:22:11 -0400 Subject: [PATCH 3/3] Move ValidateForm outside of doc ready and fix PreventSubmission calls --- validator.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/validator.js b/validator.js index b4c69ef..1d2236b 100644 --- a/validator.js +++ b/validator.js @@ -6,9 +6,9 @@ $(document).ready( function() { $("form").submit( function() { ValidateForm(); }); +}); - - function ValidateForm() { +function ValidateForm() { ValidateEmail(); ValidatePassword(); }; @@ -37,12 +37,12 @@ $(document).ready( function() { var capital_regex = /[A-Z]/; var num_regex = /[0-9]/; var min_length = 8; - var too_short = password < min_length; + var too_short = password.length < min_length; var no_capital_chars = !capital_regex.test(password) var no_numbers = !num_regex.test(password) if (too_short) { - PreventSubmission; + PreventSubmission(); $(".errors li:nth-child(2)").show(); } else { @@ -51,7 +51,7 @@ $(document).ready( function() { if (no_capital_chars) { - PreventSubmission; + PreventSubmission(); $(".errors li:nth-child(3)").show(); } else { @@ -59,11 +59,10 @@ $(document).ready( function() { }; if (no_numbers) { - PreventSubmission; + PreventSubmission(); $(".errors li:nth-child(4)").show(); } else { $(".errors li:nth-child(4)").hide(); }; - }; -}); \ No newline at end of file + }; \ No newline at end of file