mirror of
https://github.com/dzeiocom/FormManager.git
synced 2025-04-23 03:12:14 +00:00
Added functions to help set/get default value
This commit is contained in:
parent
dfa6058cf0
commit
b2c238ea13
15
FMInput.ts
15
FMInput.ts
@ -8,9 +8,7 @@ export default class FMInput {
|
|||||||
constructor(element: HTMLElement, form: FormManager) {
|
constructor(element: HTMLElement, form: FormManager) {
|
||||||
this.element = element as HTMLInputElement
|
this.element = element as HTMLInputElement
|
||||||
this.form = form
|
this.form = form
|
||||||
if (this.element.hasAttribute("data-default")) {
|
this.setToDefault()
|
||||||
this.setValue(this.getDefault(this.element.dataset.default))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,9 +39,20 @@ export default class FMInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getDefault(args: string): any {
|
getDefault(args: string): any {
|
||||||
|
if (args.startsWith("run:")) {
|
||||||
|
args = args.split("run:")[1]
|
||||||
|
return eval(args)
|
||||||
|
}
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setToDefault() {
|
||||||
|
if (this.element.hasAttribute("data-default")) {
|
||||||
|
return this.setValue(this.getDefault(this.element.dataset.default))
|
||||||
|
}
|
||||||
|
return this.setValue("")
|
||||||
|
}
|
||||||
|
|
||||||
getName(): string {
|
getName(): string {
|
||||||
return this.element.getAttribute("name") == undefined ? this.element.dataset.name : this.element.getAttribute("name")
|
return this.element.getAttribute("name") == undefined ? this.element.dataset.name : this.element.getAttribute("name")
|
||||||
}
|
}
|
||||||
|
@ -101,9 +101,6 @@ import FMInput from "./FMInput"
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager for Forms
|
* Manager for Forms
|
||||||
*
|
*
|
||||||
@ -319,8 +316,12 @@ export default class FormManager {
|
|||||||
*/
|
*/
|
||||||
public clear() {
|
public clear() {
|
||||||
this.form.querySelectorAll("[name]").forEach((el: HTMLInputElement) => {
|
this.form.querySelectorAll("[name]").forEach((el: HTMLInputElement) => {
|
||||||
el.value = ""
|
for (const name in this.inputs) {
|
||||||
el.removeAttribute("value")
|
if (this.inputs.hasOwnProperty(name)) {
|
||||||
|
const input = this.inputs[name];
|
||||||
|
input.setToDefault()
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user