| Total Complexity | 1 |
| Complexity/F | 0 |
| Lines of Code | 39 |
| Function Count | 0 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | interface SubmitButton extends HTMLElement { |
||
| 2 | removeAttribute(name: string): void; |
||
| 3 | setAttribute(name: string, value: string): void; |
||
| 4 | } |
||
| 5 | |||
| 6 | /** |
||
| 7 | * checkValidText is where we check if the text input is valid |
||
| 8 | * If it is, we enable the submit button |
||
| 9 | */ |
||
| 10 | |||
| 11 | const checkValidText = (event: Event): void => { |
||
| 12 | const bilInformasjon = event.target as HTMLInputElement; |
||
| 13 | |||
| 14 | const submitButton = window.document.getElementById( |
||
| 15 | "submitButton" |
||
| 16 | ) as SubmitButton; |
||
| 17 | |||
| 18 | console.log("checkValidText is called"); |
||
| 19 | |||
| 20 | const letters = /[A-Z]{2}\d{5}/gi; |
||
| 21 | const bilInformasjonMatchesFormat = letters.test(bilInformasjon.value); |
||
| 22 | |||
| 23 | console.log("bilInformasjon:", bilInformasjon); |
||
| 24 | console.log("bilInformasjonMatchesFormat: ", bilInformasjonMatchesFormat); |
||
| 25 | |||
| 26 | if ( |
||
| 27 | bilInformasjonMatchesFormat && |
||
| 28 | bilInformasjon !== undefined |
||
| 29 | |||
| 30 | //bilInformasjon.length === 7 |
||
| 31 | ) { |
||
| 32 | submitButton.removeAttribute("disabled"); |
||
| 33 | } else { |
||
| 34 | submitButton.setAttribute("disabled", "true"); |
||
| 35 | } |
||
| 36 | }; |
||
| 37 | |||
| 38 | export default checkValidText; |
||
| 39 |