Skip to content

Properly validate numeric metadata

Erwan Rouchet requested to merge numeric-metadata-validation into master

Closes #1167 (closed)

It took me a while to find what was wrong, especially as Vue and Webpack were not giving me good stack traces. It turns out that when you start editing a metadata, this.selectedMetadata.value is a Number because the backend returns a number for numeric metadata. When you change the value in any way, the value becomes a string, because <input type="text"> will give you a string. <input type="number"> would also give you a string. Since creating a numeric metadata has to involve typing a value at some point, then this issue only occurs when editing existing metadata. The form validation code tries to call value.trim(), but Number.prototype.trim() is not a thing.

I added some extra validation that should allow handling almost any existing JS type, including null, undefined, number, object or array and properly fail with a "Value must not be empty" error. Most importantly, I added proper number validation to avoid inexplicable "Request failed with status code 400" that could occur if you typoed your number.

Merge request reports

Loading