foxhound87 / mobx-react-form

Reactive MobX Form State Management
https://foxhound87.github.io/mobx-react-form
MIT License
1.09k stars 129 forks source link

support dynamic label and place holder (send param from component || inject from store) #547

Closed YogiHa closed 4 years ago

YogiHa commented 4 years ago

Hi there and thanks for this great package!

Maybe it is a silly question, but I really can't found how to use dynamic place holders and labels.

My current situation is that I have translations stored at mobx store, and need either inject them directly to the form or initialize form with param from component

thanks in advance!

YogiHa commented 4 years ago

for anyone encounter this, ended by doing like

export default function (params) { ... fields and plugins.. return { form: new MobxReactForm({ fields }, { plugins })} } and calling like

let form = Form('hey').form

foxhound87 commented 4 years ago

In your manner you are recreating a new form instance each time.

Maybe you can use .set(‘label’, value); on a field instance.

Anyway, what should be an example of implementation of dynamic label that you proposed?

Thank you

YogiHa commented 4 years ago

I think the best thing would be giving an option to inject directly to the form (though it is not a component)

And I know it is not the best solution in terms of performance, but haven't had another idea how to achieve my goal, and couldn't find similar cases in the docs or online

YogiHa commented 4 years ago

Using set(‘label’, value); IMO would be out of purpose of this package, meant to separate Form and Component concerns...