-
Notifications
You must be signed in to change notification settings - Fork 76
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
CollectionType just render first row #33
Comments
Hey @hugoalexmartins, Thanks for reaching out to me via email! We actually stopped using liforms very early on, we hit a couple of stumbling blocks and so abandoned the project. I do intend to revisit the project at a later date as a pet project, and I'd be more than happy to help you out, if I can! Please be aware that my PR #22 for serialising CollectionTypes as an array wasn't ever merged in, so unless the owners have changed anything it probably is still serialising as a StdObject. It'd be useful if you could do a var_dump of the Symfony $form variable and post that here. |
Hey @antonyoneill , Thanks you very much for your reply. Here is the dump($form) Please rename it to .html and you can see all. |
Thanks for sending that over @hugoalexmartins - I've had a look at that form_dump and it looks like you've got a form that has this kind of structure:
Those subtypes of WizardQuestionType I assume are the types that are coming out for I think you may mean that you expect 3 here:
I do think that the CollectionType has actually been serialised into the schema correctly, since it wouldn't make a lot of sense if you were to make a schema for each of the entries in the collection type, since they would all be the same - adding more rows (as would naturally be possible) wouldn't have a schema. (#22 is a different issue that I don't think you're experiencing here - and in hindsight I think it may have been a Symfony issue, not liform) So! I'm not convinced that the issue is with the serialisation of the Form itself! Can you give me a bit more detail about how you normalise the data (which is what is powering your wizard), and how you are attempting to render the content? I assume you're using the LiformBundle and Symfony Normalizer to normalise the data? And liform-react to render? Sorry it took so long to get back to you! |
Depending on the answers to how you normalise and render, I might suggest you move this issue into one of the other projects (though I will continue to help you) |
Hey @antonyoneill About the 5 rows to render I told you by mistake, in this case it has 3 rows. I am using LifromBundle and normalize with: For this case my json response is like this:
It should output 3 rows of wizard_questions. If I just render the form using Twig (symfony way) all the rows are rendered well, that's why I think it could be something about Liform. Also, I am using angular-schema-form to render it. Many thanks for your help. |
Also, if I remove the Liform transformer and let FOS User transform the response I have is this:
|
Hey @hugoalexmartins In my example, I use a /** @var Liform $liform */
$liform = $this->get('liform');
$symfonyNormalizer = $this->get('serializer');
// ...
$pageState->formSchema = $liform->transform($form);
$pageState->formInitial = $symfonyNormalizer->normalize($form);
return $this->render(
'MyBundle:Liform/form.html.twig',
[
'initialState' => $this->serialiseObjectToJson($pageState),
// ...
]
); Then in twig I have var container = document.querySelector('#liformEntry')
var properties = {
page: '{{ page }}',
initialState: {{ initialState | raw }},
additionalState: {}
}
MyLiformEntry.init(container, properties) Which in my case I then feed export const MyLiformWrapper = (props: Props) => (
<Liform
schema={props.schema} // this comes from initialState.formSchema
initialValues={props.initial} // this comes from initialState.formInitial
onSubmit={props.onSubmit}
baseForm={BaseForm}
syncValidation={buildSyncValidation(props.schema)}
/>
) I'm not familiar with the You'll need to find a way to set the data on the form using your tl;dr: It's important to remember that Remember what I said above about the collection type only storing a single schema, a (prototype)[https://symfony.com/doc/current/reference/forms/types/collection.html#prototype] if you like, for the entities that it represents. |
Here you can see how the ArrayTransformer selects only the first child to represent the rest of them
|
Also take a read of this section, it looks like the schema output by liform matches the schema expected by So I think your missing piece of the puzzle is setting that initial data (somehow) on the form. This example might be helpful! https://azimi.me/angular-json-schema-form/demo/demo.html |
Hey @antonyoneill Now I got a better idea of how Liform works. At first, in my case I need to use a CollectionType, which in the background is dynamic Form for a Wizard, in which I have Questions and I will have User Answers, how do I need to render multiple Questions, I thought they would come from an array to the Schema. In my case, my initialValues will be rendered by Angular Schema Forms, similar to React. In the background the Symfony serializer will normalize the Object to the Form, am I correct in this statement? In the meantime I have made my code for Symfony handle the Object for the Form, but it returns empty, is anything more to escape me? |
Also, can you tell how do you deal with "select boxes"? |
Hey @hugoalexmartins - I was on holiday last week and sick yesterday. Let me get back to you in a couple of days as I have a lot to catch up with at work. I think your questions come from entities, right? You use the Form to describe how to render the entities/questions on screen – Think of the schema as a template or scaffolding for your form. It only has knowledge to render. It's the normalised entity data that you set in the angular two-way binding that is then drawn onto the screen. For more help with this you should probably get in contact with the angular-schema-form maintainers. Provided you've set the entity in your form (which you have, judging by the This liform-react code might help you understand how React renders the select boxes (named ChoiceType here) https://github.com/Limenius/liform-react/blob/master/src/themes/bootstrap3/ChoiceWidget.js I'll try to get back to you in a few days if you're still struggling. |
Hey @antonyoneill, I think I've join all the pieces of my puzzle. I am using a form, which will attach the dump, the same one in DEV and PROD, but in PROD it triggers and error: I am using exactly the same form, and this is not making any sense to me... What issue could be this one ? |
Hey @hugoalexmartins sorry for the delay, super busy at work at the moment. Will try to get back to you this week. I suspect that you have different package versions installed on dev/prod or there's some obscure setting somewhere. I don't think it'll be a liform issue but some other difference between your environments. Unfortunately as I'm not familiar with your environments I cannot suggest a place to start |
Hey @antonyoneill its seems be something with embed data into ColletionType, I use PRE_SET_DATA event, to find out which data should be in CollectionType and add "data" options to CollectionType.
Looking to this, it looks like data is added twice, but this only way I can make this work. |
Hi, sorry for not paying attention so often :(. I am terribly busy and the section that is using Liform in our project has been stable for some time so I have to find time from my spare time to help with these issues and it is being hard. Thanks a lot @antonyoneill for caring ❤️ Basically one thing is the schema and another are the values. The schema is a json-schema representation https://json-schema.org/ and as such for a collection it describes the type of the item in a collection (an array in json-schema), but not each item itself. The schema describes the "shape" of the data, not the actual values. In a collection, the shape is defined by defined how items should be shaped, but the actual items. The information about the actual values that populate the form, that should contain the values for each item in the collection, is produced independently by this normalizer https://github.com/Limenius/Liform/blob/master/src/Limenius/Liform/Serializer/Normalizer/InitialValuesNormalizer.php Using something like this: https://github.com/Limenius/symfony-react-sandbox/blob/master/src/Controller/AdminController.php#L45 The distinction between schema and values can be seen clearly here https://mozilla-services.github.io/react-jsonschema-form/ (the extra options they use in their schema are different than in liform but the general idea applies). |
Hi, I am trying to implement a collection type field, where I can have multiple rows and each one has fields.
But, unfortunatly the collection type just give one row, not all on related rows.
This is what i get from output:
It should render 5 rows, but I just get one.
Anyone knows what might be ?
Thanks in advance.
The text was updated successfully, but these errors were encountered: