문제

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