mirror of
https://github.com/dzeiocom/FormManager.git
synced 2025-04-22 10:52:16 +00:00
Implement listeners
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
e0629e9595
commit
ed5db58b89
@ -48,6 +48,13 @@ export default class AttributesManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public onUnfocus(ev:FocusEvent) {
|
||||||
|
const target = ev.target
|
||||||
|
if (target) {
|
||||||
|
this.triggerElement(AttributeListeners.INPUT_UNFOCUS, this.form.inputs[(target as HTMLInputElement).name])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// private onChange
|
// private onChange
|
||||||
|
|
||||||
public setup() {
|
public setup() {
|
||||||
@ -61,6 +68,8 @@ export default class AttributesManager {
|
|||||||
el.element.addEventListener("keyup", ev => this.onChange(ev))
|
el.element.addEventListener("keyup", ev => this.onChange(ev))
|
||||||
el.element.removeEventListener("change", ev => this.onChange(ev))
|
el.element.removeEventListener("change", ev => this.onChange(ev))
|
||||||
el.element.addEventListener("change", ev => this.onChange(ev))
|
el.element.addEventListener("change", ev => this.onChange(ev))
|
||||||
|
el.element.removeEventListener("focusout", ev => this.onUnfocus(ev))
|
||||||
|
el.element.addEventListener("focusout", ev => this.onUnfocus(ev))
|
||||||
|
|
||||||
// loop through assignments
|
// loop through assignments
|
||||||
for (const key in this.attributesArray) {
|
for (const key in this.attributesArray) {
|
||||||
|
@ -163,8 +163,11 @@ export default class FormManager {
|
|||||||
const input = this.inputs[name];
|
const input = this.inputs[name];
|
||||||
const res = this.attributeManager.triggerElement(AttributeListeners.VERIFY, input) as boolean
|
const res = this.attributeManager.triggerElement(AttributeListeners.VERIFY, input) as boolean
|
||||||
if (input.verify() && res) continue
|
if (input.verify() && res) continue
|
||||||
|
this.attributeManager.triggerElement(AttributeListeners.INPUT_ERROR, input)
|
||||||
errored.push(input)
|
errored.push(input)
|
||||||
if(quick) return errored
|
if(quick) {
|
||||||
|
return errored
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return errored
|
return errored
|
||||||
}
|
}
|
||||||
@ -175,8 +178,8 @@ export default class FormManager {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
* @memberof FormManager
|
* @memberof FormManager
|
||||||
*/
|
*/
|
||||||
public verify(): boolean {
|
public verify(quick = true): boolean {
|
||||||
return this.validate(true).length === 0
|
return this.validate(quick).length === 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -250,11 +253,15 @@ export default class FormManager {
|
|||||||
*/
|
*/
|
||||||
public fillFromJSON(json: any) {
|
public fillFromJSON(json: any) {
|
||||||
for (const key in json) {
|
for (const key in json) {
|
||||||
if (json.hasOwnProperty(key)) {
|
if (!json.hasOwnProperty(key)) {
|
||||||
const element = json[key];
|
continue
|
||||||
if(this.inputs[key] !== undefined) this.inputs[key].setValue(element)
|
|
||||||
else console.warn(`${key} is not a valid input name`)
|
|
||||||
}
|
}
|
||||||
|
const element = json[key];
|
||||||
|
if (this.inputs[key] === undefined) {
|
||||||
|
console.warn(`${key} is not a valid input name`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
this.inputs[key].setValue(element)
|
||||||
}
|
}
|
||||||
this.attributeManager.trigger(AttributeListeners.FORM_FILL)
|
this.attributeManager.trigger(AttributeListeners.FORM_FILL)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user