@@ -14,21 +14,26 @@ const phoneCode = document.querySelector('#phone-code')
14
14
const phone = document . querySelector ( '#phone' )
15
15
const password = document . querySelector ( '#password' )
16
16
const confirmPassword = document . querySelector ( '#confirm-password' )
17
+ const formBtn = document . querySelector ( '#form-btn' )
18
+ const form = document . querySelector ( '#form' )
17
19
18
20
// -- validaciones
19
21
let usernameValidation = false ;
20
22
let emailValidation = false ;
21
23
let phoneValidation = false ;
22
24
let passwordValidation = false ;
23
25
let confirmPasswordValidation = false ;
26
+ let contriesValidation = false
27
+
24
28
// paso3.1
25
29
// funcion para validacion estados input
26
30
27
- const validacion = ( e , validacion , element ) => {
31
+ const validation = ( e , validacion , element ) => {
28
32
29
33
// const texto= usernameInput.parentElement.children[1]
30
34
const informacion = e . target . parentElement . children [ 1 ]
31
-
35
+ formBtn . disabled = ! usernameValidation || ! emailValidation || ! phoneValidation || ! passwordValidation || ! confirmPasswordValidation || ! contriesValidation ? true : false
36
+
32
37
if ( validacion . value == '' ) {
33
38
element . classList . remove ( 'correct' )
34
39
element . classList . remove ( 'incorrect' )
@@ -52,23 +57,30 @@ const validacion=(e, validacion,element)=>{
52
57
// estado
53
58
usernameInput . addEventListener ( 'input' , e => {
54
59
usernameValidation = USERNAME_REGEX . test ( e . target . value )
55
- validacion ( e , usernameValidation , usernameInput ) //e= evento, usernameValidation =validacion ,usernameInput = input
60
+ validation ( e , usernameValidation , usernameInput ) //e= evento, usernameValidation =validacion ,usernameInput = input
56
61
57
62
} )
58
63
59
64
emailInput . addEventListener ( 'input' , e => {
60
65
emailValidation = EMAIL_REGEX . test ( e . target . value )
61
- validacion ( e , emailValidation , emailInput )
66
+ validation ( e , emailValidation , emailInput )
62
67
} )
63
68
// paso3.2 evento para seleccionar el pais y codigo de telf
64
69
countries . addEventListener ( 'input' , e => {
65
70
const optionSelected = [ ... e . target . children ] . find ( option => option . selected ) ;
66
71
phoneCode . innerHTML = `+${ optionSelected . value } `
72
+ contriesValidation = optionSelected . value == '' ?false :true
73
+ console . log ( contriesValidation ) ;
74
+ countries . classList . add ( 'correct' )
75
+ phoneCode . classList . add ( 'correct' )
76
+ validation ( e , null , null ) //para que solo verifue la validacion de menos a delos paises
67
77
} )
68
78
69
79
phone . addEventListener ( 'input' , e => {
70
80
phoneValidation = NUMBER_REGEX . test ( e . target . value )
71
81
const informacion = e . target . parentElement . parentElement . children [ 1 ]
82
+
83
+
72
84
if ( phoneValidation . valueOf == '' ) {
73
85
phone . classList . remove ( 'correct' )
74
86
phone . classList . remove ( 'incorrect' )
@@ -82,15 +94,29 @@ phone.addEventListener('input',e =>{
82
94
phone . classList . remove ( 'correct' )
83
95
informacion . classList . add ( 'show-informacion' )
84
96
}
97
+
85
98
} )
86
99
87
100
88
101
password . addEventListener ( 'input' , e => {
89
102
passwordValidation = PASSWORD_REGEX . test ( e . target . value )
90
- validacion ( e , passwordValidation , password , )
103
+ validation ( e , passwordValidation , password , )
91
104
92
105
} )
93
106
confirmPassword . addEventListener ( 'input' , e => {
94
107
confirmPasswordValidation = e . target . value === password . value
95
- validacion ( e , confirmPasswordValidation , confirmPassword )
108
+ validation ( e , confirmPasswordValidation , confirmPassword )
109
+ } )
110
+
111
+ // evento para mostrar los datos en un objeto
112
+ form . addEventListener ( 'submit' , e => {
113
+ e . preventDefault ( ) //para que la pagina no vuelva a cargar
114
+ const user = {
115
+ username :usernameInput . value ,
116
+ email :emailInput . value ,
117
+ phone :`${ phoneCode . innerHTML } ${ phone . value } ` ,
118
+ password :password . value ,
119
+ phoneCode :phoneCode . value ,
120
+ }
121
+ console . log ( user ) ;
96
122
} )
0 commit comments