質問

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