@@ -19,7 +19,7 @@ function anim_out() {
1919window . onload = function ( ) {
2020 anim_in ( ) ;
2121 document . querySelectorAll ( '.inputField' ) . forEach ( field => {
22- field . querySelectorAll ( 'input, textarea' ) . forEach ( input => {
22+ field . querySelectorAll ( 'input:not([type="radio"]) , textarea' ) . forEach ( input => {
2323 if ( localStorage . getItem ( field . id ) ) {
2424 input . value = localStorage . getItem ( field . id ) ;
2525 document . querySelector ( '.fixed2' ) . classList . add ( 'visible' ) ;
@@ -39,6 +39,26 @@ window.onload = function () {
3939 } , 2000 ) ;
4040 } ;
4141 } ) ;
42+ field . querySelectorAll ( '.radioOption' ) . forEach ( radio => {
43+ const input = radio . querySelector ( 'input[type="radio"]' ) ;
44+ if ( localStorage . getItem ( field . id ) === input . value ) {
45+ field . querySelectorAll ( '.radioOption input[type="radio"]' ) . forEach ( r => r . checked = false ) ;
46+ input . checked = true ;
47+ document . querySelector ( '.fixed2' ) . classList . add ( 'visible' ) ;
48+ setTimeout ( ( ) => {
49+ document . querySelector ( '.fixed2' ) . classList . remove ( 'visible' ) ;
50+ } , 2000 ) ;
51+ } ;
52+ } ) ;
53+ field . querySelectorAll ( 'select' ) . forEach ( select => {
54+ if ( localStorage . getItem ( field . id ) ) {
55+ select . value = localStorage . getItem ( field . id ) ;
56+ document . querySelector ( '.fixed2' ) . classList . add ( 'visible' ) ;
57+ setTimeout ( ( ) => {
58+ document . querySelector ( '.fixed2' ) . classList . remove ( 'visible' ) ;
59+ } , 2000 ) ;
60+ } ;
61+ } ) ;
4262 } ) ;
4363} ;
4464
@@ -67,6 +87,17 @@ function next() {
6787 shake ( currentField ) ;
6888 return ;
6989 } ;
90+ } else if ( input . type === 'radio' ) {
91+ const radios = currentField . querySelectorAll ( 'input[type="radio"]' ) ;
92+ var checked = false ;
93+ radios . forEach ( radio => {
94+ if ( radio . checked ) checked = true ;
95+ } ) ;
96+ if ( ! checked ) {
97+ input . focus ( ) ;
98+ shake ( currentField ) ;
99+ return ;
100+ } ;
70101 } else {
71102 if ( ! input . value . trim ( ) ) {
72103 input . focus ( ) ;
@@ -117,36 +148,42 @@ function back() {
117148
118149function saveChange ( key , value ) {
119150 localStorage . setItem ( key , value ) ;
151+ console . log ( key , value )
120152 document . querySelector ( '.fixed2' ) . classList . add ( 'visible' ) ;
121153 setTimeout ( ( ) => {
122154 document . querySelector ( '.fixed2' ) . classList . remove ( 'visible' ) ;
123155 } , 2000 ) ;
124156} ;
125157
126158document . querySelectorAll ( '.inputField' ) . forEach ( field => {
127- field . querySelectorAll ( 'input, textarea' ) . forEach ( input => {
159+ field . querySelectorAll ( 'input:not([type="radio"]) , textarea' ) . forEach ( input => {
128160 input . addEventListener ( 'keydown' , function ( event ) {
129161 if ( event . key === 'Enter' ) {
130162 event . preventDefault ( ) ;
131163 next ( ) ;
132164 } ;
133- saveChange ( field . id , input . value ) ;
165+ setTimeout ( ( ) => saveChange ( field . id , input . value ) , 100 ) ;
134166 } ) ;
135167 } ) ;
136168 field . querySelectorAll ( '.checkbox' ) . forEach ( checkbox => {
137169 checkbox . addEventListener ( 'click' , function ( ) {
138170 checkbox . classList . toggle ( 'checked' ) ;
139171 const input = field . querySelector ( 'input[type="checkbox"]' ) ;
140172 input . checked = ! input . checked ;
141- saveChange ( field . id , input . checked ) ;
173+ setTimeout ( ( ) => saveChange ( field . id , input . checked ) , 100 ) ;
142174 } ) ;
143175 } ) ;
144176 field . querySelectorAll ( '.radioOption' ) . forEach ( radio => {
145- radio . addEventListener ( 'click ' , function ( ) {
177+ radio . addEventListener ( 'change ' , function ( ) {
146178 field . querySelectorAll ( '.radioOption input[type="radio"]' ) . forEach ( r => r . checked = false ) ;
147179 const input = radio . querySelector ( 'input[type="radio"]' ) ;
148180 input . checked = true ;
149- saveChange ( field . id , input . value ) ;
181+ setTimeout ( ( ) => saveChange ( field . id , input . value ) , 100 ) ;
182+ } ) ;
183+ } ) ;
184+ field . querySelectorAll ( 'select' ) . forEach ( select => {
185+ select . addEventListener ( 'change' , function ( ) {
186+ setTimeout ( ( ) => saveChange ( field . id , select . selectedOptions [ 0 ] . value ) , 100 ) ;
150187 } ) ;
151188 } ) ;
152189} ) ;
@@ -173,6 +210,11 @@ async function create() {
173210 if ( input ) {
174211 if ( input . type === 'checkbox' ) {
175212 data [ field . id ] = input . checked ;
213+ } if ( input . type === 'radio' ) {
214+ const radios = field . querySelectorAll ( 'input[type="radio"]' ) ;
215+ radios . forEach ( radio => {
216+ if ( radio . checked ) data [ field . id ] = radio . value ;
217+ } ) ;
176218 } else {
177219 data [ field . id ] = input . value ;
178220 } ;
0 commit comments