Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging passed initialValues from the schema and from props #332

Closed
skateman opened this issue Feb 27, 2020 · 23 comments
Closed

Merging passed initialValues from the schema and from props #332

skateman opened this issue Feb 27, 2020 · 23 comments
Assignees
Labels
bug Something isn't working P1 renderer React form renderer PR

Comments

@skateman
Copy link
Member

I know that the initialValues passed to the FormRender component have a higher priority. However, if this attribute is set on the component, it ignores any initialValue attributes defined on the field level in the schema, even those which aren't set on the component level.

I discussed this with @rvsia and he said this is a bug, the two levels should be merged with the component level as priority.

@rvsia
Copy link
Contributor

rvsia commented Feb 27, 2020

@Hyperkid123 What do you think?

@Hyperkid123
Copy link
Member

@skateman I was under the impression that initialValue from schema has a higher priority. I will need to think about this for a moment.

@skateman
Copy link
Member Author

Having the higher priority from the component actually makes more sense, but they should overlap and merge.

@Hyperkid123
Copy link
Member

Hyperkid123 commented Feb 27, 2020

And how do you think the merge should look like? Can you provide a simple example?

@skateman
Copy link
Member Author

So this setup:

const schema = {
  component: 'text-field',
  name: 'name',
},
{
  component: 'text-field',
  name: 'address',
  initialValue: 'Foo street'
},
{
  component: 'text-field',
  name: 'country',
  initialValue: 'Czech Republic'
};

const values = {
  name: 'John Doe',
  address: 'Bar street',
}

<FormRender schema={schema} initialValues={values}>;

Should return with the initial values:

{
  name: 'John Doe',
  address: 'Bar street',
  country: 'Czech Republic',
}

@Hyperkid123
Copy link
Member

@skateman and that is not happening right now? That is how it should work.

@skateman
Copy link
Member Author

Nope, it doesn't

@Hyperkid123
Copy link
Member

Huh, that is strange. Ok, I will take a look at what is going on there. This is expected behavior and I was under the impression that it is working. Apparently not.

@Hyperkid123 Hyperkid123 self-assigned this Feb 27, 2020
@Hyperkid123 Hyperkid123 added the bug Something isn't working label Feb 27, 2020
@Hyperkid123 Hyperkid123 added P1 renderer React form renderer PR labels Feb 27, 2020
@Hyperkid123
Copy link
Member

Hyperkid123 commented Feb 28, 2020

@skateman co I just tried the example you posted and I am getting the exact result you wanted. Can you provide more info please?

@Hyperkid123
Copy link
Member

screenshot-localhost_8080-2020 02 28-10_08_43

@skateman
Copy link
Member Author

Maybe the problem is with dotted field names? It's happening on my openstack form in MiQ.

@Hyperkid123
Copy link
Member

Lets try that

@Hyperkid123
Copy link
Member

@skateman

const schema = {fields: [{
    component: 'text-field',
    name: 'name',
  },
  {
    component: 'text-field',
    name: 'bar.address',
    initialValue: 'Foo street'
  },
  {
    component: 'text-field',
    name: 'country',
    initialValue: 'Czech Republic'
  }]};
  
const values = {
name: 'John Doe',
bar: {
    address: 'Bar street',  
    }
}

same result as before

@Hyperkid123
Copy link
Member

Hyperkid123 commented Feb 28, 2020

Maybe try update to latest version? There might have been a bug in previous.

or did you try to construct the nested value like this:

{
  'bar.address': 'value'
}

@skateman
Copy link
Member Author

Still doesn't work with the latest, I have clearOnUnmount and clearedValue={null}on the form if that helps

@skateman
Copy link
Member Author

Also it doesn't work for non-dotted fields, it just ignores any initialValue coming from the schema if the initialValues on the component is set to `{}˙.

@Hyperkid123
Copy link
Member

Hmm. Still can't reproduce. Do you think you could create an example on code sandbox? No need to use any mapper just have some basic inputs.

@skateman
Copy link
Member Author

I'm afraid it's cause by the fact that the form is being rendered on-demand 😕 so it might be miq-specific...

@Hyperkid123
Copy link
Member

@skateman is it happening in one specific field? Or is there some sort of pattern?

@skateman
Copy link
Member Author

It's a pattern, every field with an initialValue gets ignored in the cloud provider form 😕

@Hyperkid123
Copy link
Member

Well, that is a big one... Can we check it together on Monday?

@skateman
Copy link
Member Author

Wednesday the soonest, but sure. It's a tough one ...

@Hyperkid123
Copy link
Member

@skateman closing this seems like the issue was on the MIQ side. Feel free to re-open this issue if you disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1 renderer React form renderer PR
Projects
None yet
Development

No branches or pull requests

3 participants