A powerfull Form Manager https://dze.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

43 lines
915 B

  1. import FormManager from "./FormManager"
  2. export default class FMInput {
  3. element: HTMLInputElement
  4. form: FormManager
  5. constructor(element: HTMLElement, form: FormManager) {
  6. this.element = element as HTMLInputElement
  7. this.form = form
  8. if (this.element.hasAttribute("data-default")) {
  9. this.setValue(this.getDefault(this.element.dataset.default))
  10. }
  11. }
  12. setValue(value: any) {
  13. this.element.value = value
  14. this.element.setAttribute("value", value)
  15. }
  16. getValue(): any {
  17. return this.element.value
  18. }
  19. getDefault(args: string): any {
  20. return args
  21. }
  22. getName(): string {
  23. return this.element.getAttribute("name")
  24. }
  25. verify(): boolean {
  26. let val: string = this.getValue()
  27. if(val == "" && this.element.hasAttribute("required")) {
  28. return false
  29. }
  30. if(this.element.dataset.regex !== undefined) {
  31. return new RegExp(this.element.dataset.regex, 'g').test(val as string)
  32. }
  33. return true
  34. }
  35. }