Added a formatValue function

This commit is contained in:
Florian Bouillon 2019-10-08 17:31:30 +02:00
parent 914bfa8a83
commit e9a0dfe68e
No known key found for this signature in database
GPG Key ID: B143FF27EF555D16
3 changed files with 11 additions and 5 deletions

View File

@ -31,7 +31,13 @@ export default class FMInput {
* @memberof FMInput * @memberof FMInput
*/ */
getValue(): any { 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 { getDefault(args: string): any {

View File

@ -248,7 +248,7 @@ export default class FormManager {
* @returns {boolean} return if the content was sent or not * @returns {boolean} return if the content was sent or not
* @memberof FormManager * @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 if (verify && !this.verify()) return false
let ajax = new XMLHttpRequest let ajax = new XMLHttpRequest
ajax.open("POST", url, true) ajax.open("POST", url, true)
@ -264,7 +264,7 @@ export default class FormManager {
* @memberof FormManager * @memberof FormManager
*/ */
public getJSON(): any { public getJSON(): any {
const jsonObject:any = {} const jsonObject: any = {}
for (const name in this.inputs) { for (const name in this.inputs) {
if (this.inputs.hasOwnProperty(name)) { if (this.inputs.hasOwnProperty(name)) {
const input = this.inputs[name]; const input = this.inputs[name];

View File

@ -33,9 +33,9 @@ export default class FMDatalistInput extends FMInput {
getValue(): string { getValue(): string {
if (this.datalist) { if (this.datalist) {
let option: HTMLOptionElement = this.datalist.querySelector(`[value="${this.element.value}"]`) 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)
} }
} }