mirror of
https://github.com/dzeiocom/FormManager.git
synced 2025-06-07 16:49:56 +00:00
Merged from deteched branch
This commit is contained in:
commit
228a565b8c
@ -9,6 +9,7 @@ import DefaultAttribute from './attributes/DefaultAttribute'
|
|||||||
import AutosetAttribute from './attributes/AutosetAttribute'
|
import AutosetAttribute from './attributes/AutosetAttribute'
|
||||||
import CheckboxInput from './modules/CheckboxInput'
|
import CheckboxInput from './modules/CheckboxInput'
|
||||||
import NumberInput from './modules/NumberInput'
|
import NumberInput from './modules/NumberInput'
|
||||||
|
import ErrorAttribute from './attributes/ErrorAttribute'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is Mainly used for (non-npm) browser usage as it contains every buitins extensions
|
* This class is Mainly used for (non-npm) browser usage as it contains every buitins extensions
|
||||||
@ -21,19 +22,20 @@ export default class fm extends FormManager {
|
|||||||
public constructor(form: HTMLFormElement) {
|
public constructor(form: HTMLFormElement) {
|
||||||
super(form)
|
super(form)
|
||||||
this.assign(
|
this.assign(
|
||||||
|
CheckboxInput,
|
||||||
DatalistInput,
|
DatalistInput,
|
||||||
DateInput,
|
DateInput,
|
||||||
|
NumberInput,
|
||||||
RepeatInput,
|
RepeatInput,
|
||||||
SelectInput,
|
SelectInput,
|
||||||
CheckboxInput,
|
|
||||||
NumberInput,
|
|
||||||
)
|
)
|
||||||
this.setupInputs()
|
this.setupInputs()
|
||||||
this.attributeManager.register(
|
this.attributeManager.register(
|
||||||
RegexAttribute,
|
|
||||||
IgnoreAttribute,
|
|
||||||
DefaultAttribute,
|
|
||||||
AutosetAttribute,
|
AutosetAttribute,
|
||||||
|
DefaultAttribute,
|
||||||
|
ErrorAttribute,
|
||||||
|
IgnoreAttribute,
|
||||||
|
RegexAttribute,
|
||||||
)
|
)
|
||||||
this.attributeManager.setup()
|
this.attributeManager.setup()
|
||||||
}
|
}
|
||||||
|
@ -65,14 +65,14 @@ export default class FormManager {
|
|||||||
* @param {HTMLFormElement} form the form HTMLElement
|
* @param {HTMLFormElement} form the form HTMLElement
|
||||||
* @memberof FormManager
|
* @memberof FormManager
|
||||||
*/
|
*/
|
||||||
public constructor(form: HTMLFormElement, onSubmit?: (ev: Event) => void) {
|
public constructor(form: HTMLFormElement, onSubmit?: (fm: FormManager) => void) {
|
||||||
this.form = form
|
this.form = form
|
||||||
this.attributeManager = new AttributesManager(this)
|
this.attributeManager = new AttributesManager(this)
|
||||||
|
|
||||||
//Prevent default submit action
|
//Prevent default submit action
|
||||||
form.addEventListener("submit", (e: Event) => {
|
form.addEventListener("submit", (e: Event) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
onSubmit && onSubmit(e)
|
onSubmit && onSubmit(this)
|
||||||
})
|
})
|
||||||
|
|
||||||
//assign default form interface
|
//assign default form interface
|
||||||
|
@ -36,6 +36,5 @@ extends AbstractAttribute {
|
|||||||
public static identity: AttributeIdentity = {
|
public static identity: AttributeIdentity = {
|
||||||
attribute: IgnoreAttribute,
|
attribute: IgnoreAttribute,
|
||||||
dataElement: "data-ignore"
|
dataElement: "data-ignore"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,10 @@ extends AbstractAttribute {
|
|||||||
public trigger(): boolean {
|
public trigger(): boolean {
|
||||||
const regStr = this.input.element.dataset.regex
|
const regStr = this.input.element.dataset.regex
|
||||||
if (!regStr) return true
|
if (!regStr) return true
|
||||||
|
|
||||||
const regex = new RegExp(regStr, "g")
|
const regex = new RegExp(regStr, "g")
|
||||||
const test = this.input.getValue() + ""
|
const test = this.input.getValue() + ""
|
||||||
console.log(test)
|
|
||||||
return regex.test(test)
|
return regex.test(test)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,36 @@
|
|||||||
import InputIdentity from './Interfaces/InputIdentity';
|
import InputIdentity from './Interfaces/InputIdentity';
|
||||||
import DefaultInput from './DefaultInput';
|
import DefaultInput from './DefaultInput';
|
||||||
import { realType } from '../Functions';
|
import { realType } from '../Functions';
|
||||||
|
import FormManager from '../FormManager';
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @class FMDateInput
|
|
||||||
* @extends {FMInput}
|
|
||||||
*/
|
|
||||||
export default class SelectInput extends DefaultInput {
|
export default class SelectInput extends DefaultInput {
|
||||||
|
|
||||||
|
public constructor(element: HTMLSelectElement, form: FormManager) {
|
||||||
|
super(element, form)
|
||||||
|
if (element.dataset.filterElement) {
|
||||||
|
const options = element.querySelectorAll('option')
|
||||||
|
const el = form.form.querySelector<HTMLInputElement>(`[name="${element.dataset.filterElement}"]`)
|
||||||
|
if (!el) {
|
||||||
|
console.warn(`Select Input has filter Attr but can't find the element (${element.dataset.filterElement})`)
|
||||||
|
} else {
|
||||||
|
const fn = () => {
|
||||||
|
options.forEach((opt) => {
|
||||||
|
if (opt.dataset.filter === el.value || opt.dataset.filter === undefined) {
|
||||||
|
opt.removeAttribute('style')
|
||||||
|
} else {
|
||||||
|
opt.style.display = 'none'
|
||||||
|
if (this.formatValue(opt.value) === this.getValue()) {
|
||||||
|
this.setValue(undefined)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
el.addEventListener('change', fn)
|
||||||
|
fn()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public setValue(value: any) {
|
public setValue(value: any) {
|
||||||
this.element.value = this.formatValue(value)
|
this.element.value = this.formatValue(value)
|
||||||
}
|
}
|
||||||
@ -25,7 +47,7 @@ export default class SelectInput extends DefaultInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static identity: InputIdentity = {
|
public static identity: InputIdentity = {
|
||||||
input: SelectInput,
|
input: SelectInput as any,
|
||||||
tagName: "select"
|
tagName: "select"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user