rescriptbr / reform

📋 Reasonably making forms sound good
https://rescript-reform.netlify.app/
MIT License
354 stars 41 forks source link

Form State different type #156

Closed r17x closed 4 years ago

r17x commented 4 years ago

Hello, I'm use Reform.

I have some problem with type in my form.

I defined state of form like this:

module StateLenses = [%lenses
  type state = {
    userId: int,
    title: string,
    body: string,
  }
];

But, when I want request to API, the payload of request it's different.
image

I'm new corner, i didn't know how to solve this :smile: . Okay, this is an example project with my problem :smile: https://github.com/ri7nz/reform-reproduce

thank you

fakenickels commented 4 years ago

Hey there, the request looks about right with the type state. Could you explain what part of the request payload is wrong? The type of userId?

r17x commented 4 years ago

@fakenickels yes, the type of userId it's wrong.

(first, render the form) --> userId is 0 --> user change and put 2 --> userId is "2"

I'm expect userId it's int before request to the API.

fakenickels commented 4 years ago

I see, the ReForm usage and types are correct to me! Probably it is getting turned into string from the encode you are using https://github.com/ri7nz/reform-reproduce/blob/master/src/Form.re#L126. Have you tried debugging the encode function?

r17x commented 4 years ago

@fakenickels But, maybe you can check at this line https://github.com/ri7nz/reform-reproduce/blob/master/src/Form.re#L95

~for the encode, I will be check again & give it feedback, soon.~

I have been check the encode I'm using This is an example x

And this is an update for test the encode https://github.com/ri7nz/reform-reproduce/blob/master/src/Form.re#L108

DCKT commented 4 years ago

@ri7nz It's not a reform problem it's the default behavior in every browser check this https://stackoverflow.com/questions/35791767/html-input-type-number-still-returning-a-string-when-accessed-from-javascript

r17x commented 4 years ago

Hello @fakenickels & @DCKT , thank you so much for response my issue. I'm close this is issue :+1:

fakenickels commented 4 years ago

@ri7nz any questions feel free to reach me out in Discord!