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

Apply optional transformer to input before accepted #642

Merged
merged 4 commits into from
Feb 5, 2018
Merged

Apply optional transformer to input before accepted #642

merged 4 commits into from
Feb 5, 2018

Conversation

travi
Copy link
Contributor

@travi travi commented Jan 24, 2018

closes #359

@travi
Copy link
Contributor Author

travi commented Jan 24, 2018

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

@SBoudrias
Copy link
Owner

Can you add documentation for this new feature?

@travi
Copy link
Contributor Author

travi commented Jan 25, 2018

sure thing. if you're good with this approach, i'll try to get this added to the docs tonight

@SBoudrias
Copy link
Owner

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.
Copy link
Contributor Author

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?

Copy link
Owner

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.

Copy link
Contributor Author

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

@travi
Copy link
Contributor Author

travi commented Jan 30, 2018

docs have been updated. let me know if you'd like any adjustments, but i think it should be good to go otherwise.

@SBoudrias
Copy link
Owner

Thanks! I just updated piece of the documentation because the new API isn't actually asynchronous.

@SBoudrias SBoudrias merged commit 57dc2b4 into SBoudrias:master Feb 5, 2018
@travi travi deleted the input-transform branch February 5, 2018 16:45
@travi
Copy link
Contributor Author

travi commented Feb 5, 2018

thanks for working through it with me.

this is a great tool and really appreciate your work on it!

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

Successfully merging this pull request may close these issues.

Is it possible to change the color of the input beyond certain length?
2 participants