mirror of
https://github.com/dzeiocom/FormManager.git
synced 2025-04-22 19:02:15 +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) {
|
||||
this.element = element as HTMLInputElement
|
||||
this.form = form
|
||||
if (this.element.hasAttribute("data-default")) {
|
||||
this.setValue(this.getDefault(this.element.dataset.default))
|
||||
}
|
||||
this.setToDefault()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,9 +39,20 @@ export default class FMInput {
|
||||
}
|
||||
|
||||
getDefault(args: string): any {
|
||||
if (args.startsWith("run:")) {
|
||||
args = args.split("run:")[1]
|
||||
return eval(args)
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
setToDefault() {
|
||||
if (this.element.hasAttribute("data-default")) {
|
||||
return this.setValue(this.getDefault(this.element.dataset.default))
|
||||
}
|
||||
return this.setValue("")
|
||||
}
|
||||
|
||||
getName(): string {
|
||||
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
|
||||
*
|
||||
@ -319,8 +316,12 @@ export default class FormManager {
|
||||
*/
|
||||
public clear() {
|
||||
this.form.querySelectorAll("[name]").forEach((el: HTMLInputElement) => {
|
||||
el.value = ""
|
||||
el.removeAttribute("value")
|
||||
for (const name in this.inputs) {
|
||||
if (this.inputs.hasOwnProperty(name)) {
|
||||
const input = this.inputs[name];
|
||||
input.setToDefault()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user