snapcrunch / electron-preferences

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

IP address or hostname type preference value #185

Open shiyeling opened 1 year ago

shiyeling commented 1 year ago

Is your feature request related to a problem? Please describe. In my case, i need to configure a server address, might be an IP address or domain name. Now I'm using just text input, it could work but user does not have proper feedback if they messed up the address format.

Describe the solution you'd like provide validation and prompt for IP address or domain name input, which programmer could provide as an validation function in preference constructor.

Describe alternatives you've considered A call back function so that programmer could valide preference and prevent user from saving mal-formatted preference data.

Additional context NONE

lacymorrow commented 1 year ago

This is called input masking: https://css-tricks.com/input-masking/

shiyeling commented 1 year ago

This is called input masking: https://css-tricks.com/input-masking/

Thanks for letting me know. That looks intuitive and nice.

dewiweb commented 7 months ago

Is there any news about this issue? I'm also interested by IPV4(auto-adding dots each three characters) and port input fields, but I don't understand how to implement @lacymorrow suggestion in a non-jquery way:

This is called input masking: https://css-tricks.com/input-masking/

lacymorrow commented 7 months ago

@dewiweb Did you open the link? The first example is jQuery.

If you have specific questions about issues you are having and want to post a code sample, I'm happy to assist.

dewiweb commented 7 months ago

Finally I use regex to validate ipv4:port and open a info message box if user entries are unvalidated by regex. @lacymorrow Thanks for reply but I don't use jQuery !

pvrobays commented 7 months ago

@dewiweb Good that you found a workaround. I think what @lacymorrow proposed is just a few ways of how we could implement input masking in electron-preferences. However, it currently isn't.

If you want you can try to implement it and create a PR :)

lacymorrow commented 7 months ago

@pvrobays I don't think the library is completely set up for this, but I think we could do something fancy with the regular text input field to allow the user to manage the input/mask themselves.

Potentially allow them to receive change events and pass an optional value to the input.