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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top