Jump to content

InputText control types


theom
 Share

Recommended Posts

Hi

I've just started out using BJS and I really like what I've seen so far. For my application I saw the Babylon gui as a real booster since I have always ended up implementing those parts myself using what ever library I was using at the time (SVG and TheeJS for example).

Currently I'm implementing a registration form using the 2D gui and I needed a password input field where the entered characters are shown as bullets. Since the InputText control doesn't seem to have this functionality I added a flag to the control and replaced the text with bullets if the flag was set. This works fine, but it kind of felt too specific to passwords. Besides there are other well known use-cases where similar behavior changes might be needed, like entering only numbers, dates, email addresses etc. I then wonder how to best implement this. I see two ways:

  1. Modify the InputText class directly to support these different input 'modes' (or types).
  2. Create separate subclasses for each different input type.

Which of these (or some other way I didn't think of) makes more sense for Babylon?

Link to comment
Share on other sites

For the password part #1 would work, but I don't think #2 implementing different subclasses for each different type would be very extendable.

These requirements are quite common and are often implemented as "input masks" or regular expressions.  Input masks have a lot of edge cases and are harder to implement (ie: making corrections or blocking input).  Regular expressions are much easier and you may want some accompanying validation text.  Each regular expression can be evaluated when a letter is added or removed and perhaps you want a class to manage all the validations, so you could disable a submit button.

Link to comment
Share on other sites

Welcome Theom!

For the specific need of password I guess a simple PasswordBox (inheriting from Textbox) could make it as the code will be really simple and it will be easier to discover

For the regex support, I'm with @brianzinn

Link to comment
Share on other sites

Thanks Deltakosh. Glad to be here :)

I was kind of leaning towards subclassing but I agree with @brianzinn that a regular expressions is probably the way to go for the input mask.

I'll explore this a bit further and see what I can come up with.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...