swiftDialog / swiftDialog

Create user-notifications on macOS with swiftDialog
MIT License
546 stars 53 forks source link

FR: Add a `--textfield` option that requires the user to enter the same value twice ala password reset windows #377

Closed BigMacAdmin closed 2 months ago

BigMacAdmin commented 3 months ago

Is your feature request related to a problem? Please describe. Currently the best way I can figure to require the user to enter the same value in two text fields is to write a loop.

Describe the solution you'd like I would like a new --textfield option which would duplicate the text entry field and require the user put the same value in both textfields. This could be enforced similar to how regex is enforced, the user can't click "Ok" until the two text fields contain valid data.

Possible syntax:

--textfield "New Temporary Password",secure,confirminput="Confirm Password"

image

image

Describe alternatives you've considered We can create this workflow using a while loop and programming a number of attempts before erroring out the script.

bartreardon commented 3 months ago

I'll have a think about how to implement this. Might be fiddly since textfields and secure fields are actually two seperate things so having an automated "validate" property might result in duplicated code but I'll have a play with it.

bartreardon commented 3 months ago

@BigMacAdmin How does this look?

Screenshot 2024-05-19 at 4 55 01 PM

Using the confirm option will duplicate the textfield and the two fields need to match to pass validation. The label is the same as the parent textfield with the word "Confirm" prepended and uses the secondary font colour to distinguish it as a confirmation field and not a regular textfield.

Works for non-secure fields as well:

Screenshot 2024-05-19 at 5 03 46 PM

When used with a regex the regex checked only on the primary textfield. Since the secondary field will need to match the first anyway, any validation checks will be inherited.

BigMacAdmin commented 3 months ago

This looks great, and is working perfectly in testing. You're spoiling me.

My only comment is about the potential issues with multi-lingual users (doesn't really affect me), the word "Confirm" may look out of place if the rest of the dialog is in Korean for instance. I don't know if there's a simple way to overcome that, unless you wanted to make that another configurable option (because I'm sure you want to make more configurable options, right?)

bartreardon commented 3 months ago

That text is localised but only to a handful of languages. Adding in other languages is easy if i know what the translations are.

bartreardon commented 3 months ago

That reminds me, i do need to update other areas of text since things like the error message that pops up is currently hard coded. Might make that a task to complete before release.

BigMacAdmin commented 3 months ago

I didn't know you had localized support like that, thats great.

I tried again and can't seem to break this new feature, thanks again.

bartreardon commented 3 months ago

I do wonder if there will be some sort of "auto localisation using AI" thing for xcode announced at wwdc - for now though it's just putting strings into google translate and hoping for the best. 🙂