mirror of
https://github.com/dzeiocom/FormManager.git
synced 2025-07-29 00:09:53 +00:00
first commit
This commit is contained in:
46
modules/FMDatalistInput.ts
Normal file
46
modules/FMDatalistInput.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { FMAssignInterface } from './../Interfaces';
|
||||
import FormManager from "../FormManager"
|
||||
import FMInput from "../FMInput"
|
||||
|
||||
/**
|
||||
* the upgraded datalist element
|
||||
* @priority 2
|
||||
* @class FMDatalistInput
|
||||
* @extends {FMInput}
|
||||
*/
|
||||
export default class FMDatalistInput extends FMInput {
|
||||
|
||||
datalist: HTMLDataListElement
|
||||
isStrict: boolean
|
||||
|
||||
constructor(element: HTMLInputElement, form: FormManager) {
|
||||
super(element, form)
|
||||
this.isStrict = this.element.hasAttribute("data-strict")
|
||||
let id = this.element.getAttribute("list")
|
||||
let tmpDatalist = document.getElementById(id)
|
||||
this.datalist = tmpDatalist !== undefined ? tmpDatalist as HTMLDataListElement : undefined
|
||||
}
|
||||
|
||||
setValue(value: string) {
|
||||
if (this.datalist) {
|
||||
let option: HTMLOptionElement = this.datalist.querySelector(`[value="${value}"]`)
|
||||
if (option || !this.isStrict) {
|
||||
this.element.value = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getValue(): string {
|
||||
if (this.datalist) {
|
||||
let option: HTMLOptionElement = this.datalist.querySelector(`[value="${this.element.value}"]`)
|
||||
if (option) return option.dataset.value
|
||||
}
|
||||
return this.isStrict ? undefined : this.element.value
|
||||
}
|
||||
}
|
||||
|
||||
export const FMDatalistAssignement: FMAssignInterface = {
|
||||
input: FMDatalistInput,
|
||||
attributes: "list",
|
||||
tagName: "input"
|
||||
}
|
28
modules/FMDateInput.ts
Normal file
28
modules/FMDateInput.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { FMAssignInterface } from './../Interfaces';
|
||||
import FMInput from "../FMInput"
|
||||
|
||||
/**
|
||||
*
|
||||
* @class FMDateInput
|
||||
* @extends {FMInput}
|
||||
*/
|
||||
export default class FMDateInput extends FMInput {
|
||||
|
||||
setValue(value: Date) {
|
||||
this.element.valueAsDate = value
|
||||
}
|
||||
|
||||
getValue(): Date {
|
||||
return this.element.valueAsDate
|
||||
}
|
||||
|
||||
getDefault(args: string): Date {
|
||||
return new Date
|
||||
}
|
||||
}
|
||||
|
||||
export const FMDateInputAssignement: FMAssignInterface = {
|
||||
input: FMDateInput,
|
||||
type: "date",
|
||||
tagName: "input"
|
||||
}
|
73
modules/FMRepeatInput.ts
Normal file
73
modules/FMRepeatInput.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import { FMAssignInterface } from './../Interfaces';
|
||||
import FormManager from "../FormManager"
|
||||
import FMInput from "../FMInput"
|
||||
|
||||
/**
|
||||
*
|
||||
* @class FMRepeatInput
|
||||
* @extends {FMInput}
|
||||
*/
|
||||
export default class FMRepeatInput extends FMInput {
|
||||
|
||||
constructor(element: HTMLDivElement, form: FormManager) {
|
||||
super(element, form)
|
||||
|
||||
//fetch Template
|
||||
let template: HTMLElement = element.querySelector(".fmr-template")
|
||||
template.style.display = "none"
|
||||
|
||||
//fetch add button
|
||||
let addBtn = element.querySelector(".fmr-add")
|
||||
addBtn.addEventListener("click", () => {
|
||||
let node = element.insertBefore(template.cloneNode(true), addBtn) as HTMLElement
|
||||
node.classList.remove("fmr-template")
|
||||
node.classList.add("fmr-element")
|
||||
node.style.display = ""
|
||||
let del = node.querySelector(".fmr-del")
|
||||
del.addEventListener("click", () => {
|
||||
node.remove()
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
loopInputs(): FMInput[][] {
|
||||
let inputs: FMInput[][] = []
|
||||
this.element.querySelectorAll(".fmr-element").forEach((pouet: HTMLElement) => {
|
||||
let subElement: FMInput[] = []
|
||||
pouet.querySelectorAll("[data-input]").forEach((localElement: HTMLElement) => {
|
||||
subElement.push(this.form.getInit(localElement))
|
||||
});
|
||||
inputs.push(subElement)
|
||||
})
|
||||
return inputs
|
||||
}
|
||||
|
||||
setValue(value: any[][]) {
|
||||
for (const index in value) {
|
||||
if (value.hasOwnProperty(index)) {
|
||||
const element = value[index];
|
||||
console.log(index,element, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getValue(): any[][] {
|
||||
let values: any[][] = []
|
||||
let elements = this.loopInputs()
|
||||
for (const line of elements) {
|
||||
let lineArray: any[] = []
|
||||
for (const col of line) {
|
||||
lineArray.push(col.getValue())
|
||||
}
|
||||
values.push(lineArray)
|
||||
}
|
||||
return values
|
||||
}
|
||||
}
|
||||
|
||||
export const FMRepeatInputAssignment: FMAssignInterface = {
|
||||
input: FMRepeatInput,
|
||||
classes: "fm-repeat",
|
||||
tagName: "div"
|
||||
}
|
Reference in New Issue
Block a user