The value does not match the field type Number when null value

I have a form with a rating input box. It is not a required field. I’ve noticed that if the user leaves it blank, I get an exclamation mark in the content manager with the following message: “The value does not match the field type Number”. It gives me the option to convert in which it changes the value to 0 or to clear the content.

I would like to leave it blank if the user does not enter any number in the input box. How would I do that?

It’s prob because that input box returns a string, in this case an empty string, but still a string (and in your collection the field is a number, I guess). Just test more or less like so:

if(!$w('#someinput').value ){$w('#someinput').value = undefined };

This replaces an empty string with undefined, which is allowed in a collection number field.

Yes, that seems to be the problem. Is that a feature or a bug? It seems to me that if the input box is set to accept only numbers it should return undefined if it is left blank.

Anyway, I did something similar to what you proposed. When the page loads I used setFieldValue to force undefined. That way if it is left blank it won’t give a mismatch error.

$w('#dataset1').setFieldValue("rating", undefined);

It is documented as such, so it’s a feature, I guess, but I do agree that you would expect a numeric value instead of a string when input is set to Number. The element is called “TextInput”, so the “Number”-setting is just a check on input, not a change in return value.