A bit of help needed !
Hello, I'm not new to React / Mobx or JS but i've found that most examples seems are not clear to me.
i mean, i like to dig into the demo code / source code to understand how things works, but, even with the quick start section or in the documentation, i wasen't able to use or set up any single form.
it's not the code, it's where the code is supposed to be. in my case i've thinked about something like this :
--/forms/
----/validators/
----/MyForm.jsx
----/MySecondForm.jsx
And use it as component, with few methods like onSubmit or something else.
Maybe, i've forgot something but i really need the most simple example to understand what i've done wrong !
Also it seems that the dollar sign is an issue to me, even after the compilation with babel :
- react
- latest
- transform-class-properties
- transform-decorators-legacy
it doesn't seems to work, i've always got TypeError: form.$ is not a function
But IMO a simple repo with the most basic example ( 3 / 5 files ) would help many people :)
Thanks you and have a nice day !
Hi @Bouhnosaure
I don't think the dollar sign is a problem for the compilation, it seems you are not using the form instance correctly, you can do a console.log(form) to check.
Have you read the tutorial? It's a step-by-step guide to setup a minimal form with a simple component.
Anyway I will update the docs in the future with small simple examples with code playground.
Hello @foxhound87 !
Yes i've read it ( that's why i've talked about where do i put things )
this is the screen capture : http://prntscr.com/el6sr1 with the console.log(form)
That's an empty object.
The reason is you are using different files/modules, so you need to export the instance in your form.js file:
export default new LoginForm({ fields }, { plugins });
Refresh the page :p (different image)
I've finally manage to get things working, i've a form i can submit things it's okay :)
My last question now is about using the methods onSubmit or init. i've seen the examples that you've put some logic in the form's classes, is it a good practice ?
I mean, if i've to create a sort of CRUD the Create is not a problem but for the Update part, do i have to load the data from the form's classe by instanciate the classe with some id Or can i use some props methods on the component to handle this outside ?
( also there is a typo with onSubimt at the end of this page form.html )
And thanks you for the help !
Thank you for reporting the typo.
I don't know if I understood your problem, but if you are creating a CRUD, I think it's better to use the separated mode for defining fields so you can pass the values object on form initialization if you need to populate it, otherwise use the update() method if you need to change the form data.
You don't need to put more logic in the form class until you need custom behaviors.
Okay i see now,
i've read about decoupling-handlers. i've talked about that because i wanted to separate "actions" ( like loading the data / handle submit / ... ) and the behavior of the form itself.
Thanks for your explanations !
If you want more control and decouple stuff, I suggestion you to read how to define custom bindings, so you can add different handlers for each bindings
Thanks !
I've seen this in the demo project, but i thinks i'll stick on basic things, but i think, maybe i will have some trouble with loading data into <select/> items ( maybe not )
Also i let a screenshot a working example ( simple ) with external binding and initial data