codecks-io / react-reform

Helps you create powerful themes for pleasant to use forms
http://react-reform.codecks.io
135 stars 7 forks source link

Different set of fields #12

Closed jorgecuesta closed 7 years ago

jorgecuesta commented 7 years ago

Hi @danielberndt I have an issue when need pass to form as children a list of inputs and based on my own component logic prevent some of this input be a children.

Sample:

if(businessLogic) { 
  inputs=[<input name='name' is-required />, <input name='description' has-minLenght={10}' />];
} else {
  inputs=[<input name='name' is-required />];
}

<Form {...formProps}>
 {inputs}
</Form>

In this example when businessLogic is true I render 2 inputs that have validations, after something change an businessLogic is now false, in this case I render just 1 input.

The problem is that Form doesn't refresh this.state.fields and every time has validations of 2 inputs.

The other case is oppose, when I first pass just 1 input and after pass 2 it only take 1 in consideration to apply validations.

I be reading Form.js to see some way to make it update this.state.fields list but don't see anything.

Thanks.

jorgecuesta commented 7 years ago

@danielberndt I found form.reset() to can clean this.state.fields of Form and force that it refresh validations.

danielberndt commented 7 years ago

Uh, that's an interesting case. I'm currently working on a v1.0 and I'll make sure to find a less hacky workaround!

jorgecuesta commented 7 years ago

Thanks. When you get the right way please let me know

Jorge Cuesta - From IPhone Software Engineer @ Okkralabs Skype: phiroarg Mobil: +543794767536 Corrientes, Corrientes (3400) - Argentina

El 28 dic. 2016, a las 07:53, Daniel notifications@github.com escribió:

Uh, that's an interesting case. I'm currently working on a v1.0 and I'll make sure to find a less hacky workaround!

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

danielberndt commented 7 years ago

Have a look at this example for v1.0. Is it more or less doing what you've been attempting?

jorgecuesta commented 7 years ago

Yes this example works and I use it as is, but our case is a bit more complex. We made a Pseudo Grid with form where for each record have a set of same fields replicated. Last column has a button to remove row. When we change amount of rows, create again all fields less one. On validations after some change on renderForm retrieve validations of all previous fields. Let me some time to make it in some .js and share with you to talk about it.

But the main idea is get an upload grid form. Just some fields to fill on each file selected to be uploaded.

danielberndt commented 7 years ago

fyi, I just updated some code in v1.1.1 to properly unregister inputs (and their validations) once they get unmounted.

Closing this for now, please re-open should you come across any issues :)

jorgecuesta commented 7 years ago

Thanks Daniel, I will be checking it in some days and let you know.

On Jan 9, 2017, at 7:09 AM, Daniel notifications@github.com wrote:

Closed #12 https://github.com/codecks-io/react-reform/issues/12.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/codecks-io/react-reform/issues/12#event-915704715, or mute the thread https://github.com/notifications/unsubscribe-auth/AJaO8MbS8eio-UjiK3QWLOyG3FX4bL1Aks5rQgdpgaJpZM4LWczP.