Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top