Pergunta

So I'm not even sure how to word this. I am trying to validate form data with a JSON Schema. I use Dojo to create the form and fetch it's contents when the user clicks submits. However all the data in the form are returned as strings. Thus when my schema finds a field that should be a number it throws an error because it is technically a string even if the input is '123'. Is there a way to get form data while preserving it's primitive type?

array.forEach(formData, function(item) {
    postData[String(item.title)] = domAttr.get(item, "value");
});

Any ideas?

Foi útil?

Solução

Use parseInt() or parseFloat() when validating the string. Check it out here.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top