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

Value restrictions and data validation #16

Closed
hradac opened this issue Nov 18, 2011 · 8 comments
Closed

Value restrictions and data validation #16

hradac opened this issue Nov 18, 2011 · 8 comments

Comments

@hradac
Copy link

hradac commented Nov 18, 2011

Using a select drop down limits the user to certain set of acceptable answers. While I really like selectToAutocomplete I find that I miss that aspect of select boxes. If I type a single letter and submit the form the very first option in the list is submitted even if that option did not match the single letter I typed. Is there a way to ensure the user selects one of the options available, or at least that the first option in the subset of options gets submitted?

For example, my options start with "United States" yet when I type and submit "f" it is "United States" that is submitted, not "France".

To clarify the flow goes like this: I type "f" then click off the field where it stays "f". I know that if I type "f" and hit "enter" that "France" auto fill the field. So I guess the question is, is there a way to get "France" to auto fill if the user simply clicks off the field while typing?

@jamieholst
Copy link
Owner

Sounds strange.. I'm not getting the same behavior.. whenever I leave the field it resets the value unless an exact match has been typed out in full (or if I selected an option of course).

Two questions:

  1. Do you have a blank option in the original 'select' tag?
  2. Which browser are you using?

@hradac
Copy link
Author

hradac commented Nov 20, 2011

I was using Firefox 7 on a Mac. There was no blank select. It was like I
described, the very first option would be the one that's submitted. This
might be specific to clicking out of the field when a partial answer has
been entered. I did not notice this behavior when I typed a partial entry
and hit return. In this case it would fill the nearest selection.
On Nov 20, 2011 5:16 AM, "Jamie Appleseed" <
[email protected]>
wrote:

Sounds strange.. I'm not getting the same behavior.. whenever I leave the
field it resets the value unless an exact match has been typed out in full
(or if I selected an option of course).

Two questions:

  1. Do you have a blank option in the original 'select' tag?
  2. Which browser are you using?

Reply to this email directly or view it on GitHub:

#16 (comment)

@hradac
Copy link
Author

hradac commented Nov 22, 2011

I haven't looked at the source so I'm just speculating, but perhaps adding or adjusting the event handler for the blur event of the text input would work? If the value of the text field doesn't match one of the suggested answer then make the text field's value the nearest matching suggestion. Only searching through the subset of suggested answers will reduce the processing hit this will incur.

Don't know if this is helpful at all, but it was an idea I had.

@jamieholst
Copy link
Owner

Seems like a plausible solution. If there's a blank option I think it should always revert to that unless the full name has been typed. But in case there's only value options, then it should handle this case intelligently by somehow selecting the most relevant match.

@hradac
Copy link
Author

hradac commented Nov 22, 2011

I find that usually blank options are place holders. They're there so the user doesn't think a value has been filled for them. But who knows, there could be use case for either way. Maybe an option on instantiation of the selectToAutocomplete object to set that preference would be good? I know in my case I would rather the nearest match be filled instead of a blank option.

@dontangg
Copy link
Contributor

dontangg commented Dec 9, 2011

I think that when an invalid string has been typed and the field blurs, it should just revert back to whatever the last valid response was. This allows the user to start typing and then 'cancel' their action.

@hradac
Copy link
Author

hradac commented Dec 9, 2011

I think that makes sense when the string is completely invalid. If the string is a partial match to something then I think the nearest match should be filled.

@jamieholst
Copy link
Owner

I'm personally in favor of @dontangg's approach. @hradac my worry is that we make an active choice for the user based on what is essentially a guess. In the approach presented by @dontangg we simply revert back to the user's previous choice.

However, there's a "handle_invalid_input" function, so you can overwrite the default behavior if you want to do something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants