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

Hook form: Allow to get current value from fieldname #5

Closed
wants to merge 1 commit into from

Conversation

infothien
Copy link
Contributor

@infothien infothien commented May 21, 2021

Aim to solve this one https://github.com/scoville/ats/pull/143

I also added demo in example

Screen.Recording.2021-05-22.at.10.10.58.mov

@infothien infothien self-assigned this May 21, 2021
@infothien infothien requested a review from gaku-sei May 22, 2021 01:05
@infothien infothien marked this pull request as ready for review May 22, 2021 01:05
Copy link

@Hach7ko Hach7ko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@gaku-sei gaku-sei changed the title feat(HookForm): allow to get current value from fieldname Hook form: Allow to get current value from fieldname May 24, 2021
@@ -36,6 +36,7 @@ module Form = {
clearErrors: (. string) => unit,
setError: (. string, Error.t) => unit,
reset: (~defaultValues: Js.Dict.t<Value.t>=?, unit) => unit,
getValues: (~fieldName: string) => string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry Thien, this will not always return a string, it can return any valid JS Object, so the type should be option<Js.Json.t> and we need some decoders here.

Also we could add getAllValues(~fieldNames: array<string>): array<option<Js.Json.t>> as the original function can accept an array 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaku-sei -san. Sorry i might miss sth but I get the one when try to return type option<...>
Hooks_res_—_rescript-hook-form 🙇

Also you meant get another one called getAllValues side by side with getValues Kevin-san?

Actually the: getValues in react-hook-form are quite flexible

getValues(name: string | array<string>|undefined) => object
_ only string name: 1 return data for that field
_ array string field names: return object that contains all fields
_ undefined: obj all values in the form

I tried to achieve it but cannot even I just tried achieve 1 and 3 which I used to define

getValues: (~fieldName: string=?,()) => string,

but somehow when using it getValues() => it doesnt return me the obj that contain whole form

@gaku-sei gaku-sei closed this May 25, 2021
@gaku-sei gaku-sei deleted the get_current_value_of_field_name branch May 25, 2021 12:34
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.

3 participants