teslamotors / informed

A lightweight framework and utility for building powerful forms in React applications
https://teslamotors.github.io/informed
MIT License
949 stars 172 forks source link

Enhance error message on `formApi.setValue` #155

Closed blakeyoder closed 2 years ago

blakeyoder commented 5 years ago

I've really enjoyed using your library. I'm currently working on a form heavy project and it's been a dream to work with.

I wanted to find a way to contribute and say thanks for all the time you put in to this. I've found something that would make the dev process a little easier and wanted to get your input. Would love to implement if approved.

When I attempt to set a value via the formApi on a field that doesn't exist I get the error TypeError: _this2.fields.get(...) is undefined. It would be nice if it logged out the attempted value in such a way that on formApi.setValue('nonexistent_field', 'foo') the api logged an error of the form Attempted to set a field that does not exist: nonexistent_field'

Thoughts?

joepuzzo commented 5 years ago

Soo I have been meaning to get better error messages. Its one thing im aware of but have not had the time to do. I would also have to make sure that nowhere in the code .get is called and is then checked for undefined ( I think it is btw ) because if some of the code relys on this ( which i think it does ) then it would break functionality.

Ps. I might be incorrect saying that some of the code relys on fields.get to return undefined.. it may just be the ObjectMaps getter. I just want to make sure we are aware that it might be.

blakeyoder commented 5 years ago

Yeah, that's a good point. If you're checking for undefined from .get then it needs to be approached in a smarter way.

Anyways, if you come up with a roadmap for enhancing error messages and would like some help, I'd love to contribute on that end.

joepuzzo commented 5 years ago

Ok thanks! I will let you know if i come up with something 👍