Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input mask for text entry fields #415

Merged
merged 17 commits into from
Mar 8, 2013
Merged

Add input mask for text entry fields #415

merged 17 commits into from
Mar 8, 2013

Conversation

jdzak
Copy link
Contributor

@jdzak jdzak commented Feb 28, 2013

Having a way to specify an input mask for text boxes would provide users a visual cue when entering certain types of data (e.g. phone numbers or zip code), and it would constrain what is entered to either alpha/numeric/both as well as the length of input.

One possible way to implement this would be to add a property on answer..

q 'If you have a phone the user would see..
a :string, :input_mask => '(999)999-9999'

# Produces
# (___) ___ - ____

As an extra, it would be nice to control the placeholder character. So for example, instead of having an underscore as the placeholder, you could use 'Y' if you need the user to enter a year.

@jdzak
Copy link
Contributor Author

jdzak commented Feb 11, 2013

It looks like NCS Navigator Cases uses a jQuery plugin called masked input to implement input masks.

@jefflunt
Copy link
Contributor

Would something like this prevent users from entering (to follow on the phone number example):

999.999.9999 or 999 999 9999 or +1 (999) 999-9999 or any international numbers like the examples at http://www.howtocallabroad.com/uk/

I realize this feature request isn't about phone numbers per se. My question is more about if input_mask is a regex or something else, and what does it feed into? Is it only for client-side validation, or should it also pass to server side as well?

@jdzak
Copy link
Contributor Author

jdzak commented Feb 11, 2013

My question is more about if input_mask is a regex or something else

The mask isn't a regex, it's its own format. Here's a snippet of text taken from the input mask plugin page.

    a - Represents an alpha character (A-Z,a-z)
    9 - Represents a numeric character (0-9)
    * - Represents an alphanumeric character (A-Z,a-z,0-9)

Is it only for client-side validation, or should it also pass to server side as well?

There wouldn't be any validation on client or server side.

@rsutphin
Copy link
Contributor

999.999.9999 or 999 999 9999 or +1 (999) 999-9999 or any international numbers

It would prevent those, yes. For the first two, it shouldn't matter — they are semantically equivalent to the example mask. It would not force the user to enter special punctuation (and so have to guess the expected punctuation). Entry would go like this:

  • Start: (___) ___-____
  • Enter 3: (3__) ___-____
  • Enter 1: (31_) ___-____
  • Enter 2: (312) ___-____
  • Enter 5: (312) 5__-____

Etc.

If your application needed to support phone numbers with country codes, you'd need a different mask (or maybe no mask at all).

Question: why does this need to be Surveyor itself? In NCS Navigator, we support input masks, but not by associating a mask to each answer. Instead, we use JavaScript to attach the masks based on semantics derived from custom_classes. This makes changing them simpler (no new versions of surveys needed, no line-by-line review unless a class needs to be broken up) with no downsides that I can see.

@jdzak
Copy link
Contributor Author

jdzak commented Feb 12, 2013

The main motivation was to have a way to specify input masks for answers in surveyor (iOS). As an alternative, we discussed passing the :custom_class attribute to surveyor (iOS) and having specific class names which would create input masks for answer text boxes, but that seemed like a limited solution.

@yoon
Copy link
Member

yoon commented Feb 16, 2013

@jdzak @rsutphin What do you think of the syntax in: http://www.meiocodigo.com/projects/meiomask/

@yoon
Copy link
Member

yoon commented Feb 16, 2013

related to #342

@jdzak
Copy link
Contributor Author

jdzak commented Feb 18, 2013

The syntax seems straight forward. If we do decide to adopt this, would nu_surveyor only have to implement the mask rules?

@rsutphin
Copy link
Contributor

The syntax seems fine, though I'm not a big fan of the behavior of meiomask — I'd prefer one that shows the mask to the user (as underscores + punctuation) rather than just silently rejecting input it doesn't like.

@jdzak
Copy link
Contributor Author

jdzak commented Feb 25, 2013

After talking with @yoon and @rsutphin I'm going to implement this with the jquery.maskedinput plugin and the new syntax will look like..

q "What is your phone number?"
a :string, :input_mask => '(999)999-9999'
q "How old are you?"
a :integer, :input_mask => '999', :placeholder => '#'

The default placeholder for an input mask will be underscores. Specifying :placeholder without :input_mask will do nothing.

jdzak pushed a commit that referenced this pull request Feb 28, 2013
jdzak pushed a commit that referenced this pull request Feb 28, 2013
jdzak pushed a commit that referenced this pull request Feb 28, 2013
@yoon
Copy link
Member

yoon commented Mar 4, 2013

Thanks for this - Some features are failing against the current master. A cucumber feature would be helpful to demonstrate how this is to be used. Maybe even an example in the kitchen sink.

Answer#placeholder might be ambiguous (confused with something like #hint). I propose we rename it to #input_mask_placeholder as it is really tied to that implementation. The limit might be removed in the future, so it might be good to leave it off for now.

Another note, the translations branch will soon be merged, which removes the a_text helper. It's not in master yet, so depending on the timing, I can take on this one.

@jdzak
Copy link
Contributor Author

jdzak commented Mar 5, 2013

@yoon I implemented all your suggestions. Ready for review.

yoon pushed a commit that referenced this pull request Mar 8, 2013
* 415-input_masks:
  rails 3.0 doesn't use 'change' migration syntax
  Fix input mask export test. #415
  Shorten test survey. #415
  Fixed masked input javascript path. #415
  Changed name of data attributes to conform with what formtastic generates. #415
  Updated survey json representation to include new placeholder name. #415
  Testing complete input mask functionality. #415
  Test that input_mask and input_mask_placeholder are serialized. #415
  Add input mask example in kitchen sink survey. #415
  Rename input mask placeholder attribute. #415
  Remove input mask placeholder database length limit. #415
  Simplify. #415
  Use data tags to store input_mask and placeholder on tag for unobtrusive js. #415
  Cleanup input mask javascript. #415
  Serializing input_mask and placeholder attributes on Answer. #415
  Adding masked input behavior to answers with input_mask attribute. #415
  Adding input_mask and placeholder attributes to Answer. #415
@yoon yoon merged commit be58f10 into master Mar 8, 2013
yoon pushed a commit that referenced this pull request Mar 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants