mirror of
https://github.com/dzeiocom/FormManager.git
synced 2025-04-23 03:12:14 +00:00
Added a formatValue
function
This commit is contained in:
parent
914bfa8a83
commit
e9a0dfe68e
@ -31,7 +31,13 @@ export default class FMInput {
|
||||
* @memberof FMInput
|
||||
*/
|
||||
getValue(): any {
|
||||
return this.element.value
|
||||
return this.formatValue(this.element.value)
|
||||
}
|
||||
|
||||
formatValue(value: any): any {
|
||||
if (!isNaN(Number(value))) return Number(value)
|
||||
return value
|
||||
|
||||
}
|
||||
|
||||
getDefault(args: string): any {
|
||||
|
@ -248,7 +248,7 @@ export default class FormManager {
|
||||
* @returns {boolean} return if the content was sent or not
|
||||
* @memberof FormManager
|
||||
*/
|
||||
public submit(url: string, callback?: (this: XMLHttpRequest, ev: ProgressEvent) => any, verify: boolean = true): boolean {
|
||||
public submit(url: string, callback?: (this: XMLHttpRequest, ev: ProgressEvent) => void, verify: boolean = true): boolean {
|
||||
if (verify && !this.verify()) return false
|
||||
let ajax = new XMLHttpRequest
|
||||
ajax.open("POST", url, true)
|
||||
@ -264,7 +264,7 @@ export default class FormManager {
|
||||
* @memberof FormManager
|
||||
*/
|
||||
public getJSON(): any {
|
||||
const jsonObject:any = {}
|
||||
const jsonObject: any = {}
|
||||
for (const name in this.inputs) {
|
||||
if (this.inputs.hasOwnProperty(name)) {
|
||||
const input = this.inputs[name];
|
||||
|
@ -33,9 +33,9 @@ export default class FMDatalistInput extends FMInput {
|
||||
getValue(): string {
|
||||
if (this.datalist) {
|
||||
let option: HTMLOptionElement = this.datalist.querySelector(`[value="${this.element.value}"]`)
|
||||
if (option) return option.dataset.value
|
||||
if (option) return this.formatValue(option.dataset.value)
|
||||
}
|
||||
return this.isStrict ? undefined : this.element.value
|
||||
return this.isStrict ? undefined : this.formatValue(this.element.value)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user