devvit icon indicating copy to clipboard operation
devvit copied to clipboard

Number fields in app configurations silently default to `0` if no value is input by the user

Open shiruken opened this issue 1 year ago • 0 comments

Info

App configuration fields of type number only allow inputting numeric values. However, if the user clears the field and clicks submit, Devvit silently sets the value to 0 without any indication. The user would not see this change unless they refresh the settings page.

For the app developer, this is impossible to handle when 0 is a valid value for the field. This breaks using input validation to make a field required since event.value = 0.

Potential Fix

settings.get() and settings.getAll() suggest that undefined is a valid value for settings:

https://github.com/reddit/devvit/blob/8ca9b5e50acee0e950467ef8be98e4d996d977f8/packages/public-api/src/types/settings.ts#L58

https://github.com/reddit/devvit/blob/8ca9b5e50acee0e950467ef8be98e4d996d977f8/packages/public-api/src/types/settings.ts#L46

Devvit should set fields of type number equal to undefined when the submitted field was empty. This will allow for using input validation to require the field when 0 is a valid value for the field.

shiruken avatar Jul 26 '24 18:07 shiruken