-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Apply optional transformer to input before accepted #642
Conversation
i added a test for the actual application of the transformer for the input, but i'm not familar enough with your test suite to know if that covers the functionality full in line with your normal approach. is there any additional testing that you want to be added? if you're good with this approach, i'm happy to follow up and add this to the docs |
Can you add documentation for this new feature? |
sure thing. if you're good with this approach, i'll try to get this added to the docs tonight |
Yes, I think the approach and UT are good. |
README.md
Outdated
@@ -113,12 +113,13 @@ A question object is a `hash` containing question related values: | |||
Array values can be simple `strings`, or `objects` containing a `name` (to display in list), a `value` (to save in the answers hash) and a `short` (to display after selection) properties. The choices array can also contain [a `Separator`](#separator). | |||
- **validate**: (Function) Receive the user input and answers hash. Should return `true` if the value is valid, and an error message (`String`) otherwise. If `false` is returned, a default error message is provided. | |||
- **filter**: (Function) Receive the user input and return the filtered value to be used inside the program. The value returned will be added to the _Answers_ hash. | |||
- **transformer**: (Function) Receive the user input and return the transformed value to be used inside the program. The value returned will be added to the _Answers_ hash. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updating this documentation raises a question for me about the behavior, as it has been added.
my intent with the transformer is to format what is shown to the user while they are typing into the Input (things like those listed in #359: change color after some # of characters, prevent typing beyond another # of characters, maybe provide an indication of the remaining characters like "15 characters left"). i would expect the formatting to be removed before the text was added to the Answers hash or be used elsewhere in the program. essentially i would only want the formatting to be shown while typing and removed after the input is considered answered.
since i don't have full context about how things are wired together, do i need to modify the implementation at all to have it behave according to those expectations? are there other examples that i missed that behave in that way and i should model the docs description from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this only applies to the view layer. It doesn't modify the actual answer.
As such, this function cannot be used to prevent the user from entering more than X characters. It could only be used to modify the style of the input text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As such, this function cannot be used to prevent the user from entering more than X characters. It could only be used to modify the style of the input text.
great clarification. so, my understanding was mostly in line with my goal, but i hadn't considered that angle. it doesn't prevent the overall goal, but very worth clarifying.
i'll get this description updated
docs have been updated. let me know if you'd like any adjustments, but i think it should be good to go otherwise. |
Thanks! I just updated piece of the documentation because the new API isn't actually asynchronous. |
thanks for working through it with me. this is a great tool and really appreciate your work on it! |
closes #359