snapcrunch / electron-preferences

A simple, consistent interface for managing user preferences within an Electron application.
MIT License
122 stars 29 forks source link

Support validation on all types of fields #200

Open lfeigen opened 1 year ago

lfeigen commented 1 year ago

Is your feature request related to a problem? Please describe. We have one setting that is a proxy address. This is a "text" field in electron-preferences. However, this allows the user to set values that are not valid proxy addresses.

Describe the solution you'd like Just as "list" items have validation support, so should all fields.

Describe alternatives you've considered We've worked around this for now by not using the "save" functionality of electron-preferences and, instead, providing a "Save" button of our own. If they click this button with a bad value set for one of the fields, we pop up a dialog explaining the issue. It is not bad, but not as smooth as it could be.

pvrobays commented 1 year ago

Hi @lfeigen

Adding validation support is an option, where you can pass your own validation handler function with the config.

However, this one seems better to solve with a mask input field. I'm not sure if HTML input element by default has a mask property, but I'm sure there are libraries available that do this.

If I have some free time, I'll try to implement this.