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

TypeError: Cannot read property 'position' of undefined (Bi-directional loop) #45

Open
baktash93 opened this issue Aug 27, 2019 · 18 comments
Labels
P: High S: approved The issue has been validated. T: bug Functionality that does not work as intended/expected

Comments

@baktash93
Copy link

baktash93 commented Aug 27, 2019

Greetings.
I am trying to use the bi-directional loop with an .odt file but can't seem to get it working as I've started with the provided examples in the docs but it doesn't work as expected and produces the following error:

TypeError: Cannot read property 'position' of undefined
at Object.splitMarkers (<project>/node_modules/carbone/lib/extracter.js:228:41)
at <project>/node_modules/carbone/lib/builder.js:41:50
at Object.preprocessMarkers (<project>/node_modules/carbone/lib/parser.js:286:5)
at <project>/node_modules/carbone/lib/builder.js:38:18
at <project>/node_modules/carbone/lib/parser.js:39:7
at process._tickCallback (internal/process/next_tick.js:61:11)

Environment information:

Angular v8
LibreOffice calc generation .odt template
Node.js 10.15.0

Your quick response and help is very much appreciated.

@Dobby85
Copy link

Dobby85 commented Aug 27, 2019

Hi, can you give your template and your sample JSON so we can try to reproduce it ?

@baktash93
Copy link
Author

Yeah sure, the .odt is the same as the one from the online example:

 {d[i].models[i].brand} | {d[i+1].models[i].brand}
 {d[i].models[i].name} | {d[i+1].models[i].name}
 {d[i].models[i+1].name } | {d[i+1].models[i+1].name }

And the data supplied to the .odt is as follows:

[
  {
    "brand" : "Toyota",
    "models": [ 
      {"name" : "Prius 2" }, 
      {"name" : "Prius 3" }
    ]
  },
  {
    "brand" : "Tesla",
    "models" : [ 
      {"name" : "S" }, 
      {"name" : "X" }
    ]
  },
  {
    "brand" : "Lumeneo",
    "models" : [ 
      {"name" : "Smera" }, 
      {"name" : "Néoma" }
    ]
  }
]

@Dobby85
Copy link

Dobby85 commented Aug 27, 2019

It looks like there is a bug with that... We already know bi-directional loop does not work in .ods file. We will try to find a solution as soon as possible!

@baktash93
Copy link
Author

OK looking forward to it.

@steevepay steevepay added P: High S: on hold The issue is on hold until further notice T: bug Functionality that does not work as intended/expected labels Oct 8, 2019
@steevepay
Copy link
Member

Hi @baktash93

Just to give you some updates, we will fix this issue maybe on the next release.
If you can't wait the fix, feel free to fork the project and contribute :)

@steevepay steevepay added S: approved The issue has been validated. and removed S: on hold The issue is on hold until further notice labels Oct 9, 2019
@JosselinTD
Copy link

I had it working with this :

{d.title[i].text} {d.title[i+1].text}
{d.content[i].content[i].text} {d.content[i].content[i+1].text}
{d.content[i+1].content[i].text} {d.content[i+1].content[i+1].text}
{
  title: [{text: 'Salutation'}, {text: 'lang'}],
  content: [
    {content: [{text: 'Hello'}, {text: 'en'}]},
    {content: [{text: 'Bonjour'}, {text: 'fr'}]}
  ]
}

I never use a direct value from an array. Array contains Object which contains the value to use.

For the doc example, try by using something like that :

{
  myArray : [{"brand": etc...}, {"brand": etc...]
}

and changing the template with d.myArray[i]

@steevepay steevepay mentioned this issue Dec 18, 2019
21 tasks
@waltermaldonado
Copy link

waltermaldonado commented Jan 16, 2020

I had it working with this :

{d.title[i].text} {d.title[i+1].text}
{d.content[i].content[i].text} {d.content[i].content[i+1].text}
{d.content[i+1].content[i].text} {d.content[i+1].content[i+1].text}

{
  title: [{text: 'Salutation'}, {text: 'lang'}],
  content: [
    {content: [{text: 'Hello'}, {text: 'en'}]},
    {content: [{text: 'Bonjour'}, {text: 'fr'}]}
  ]
}

I never use a direct value from an array. Array contains Object which contains the value to use.

For the doc example, try by using something like that :

{
  myArray : [{"brand": etc...}, {"brand": etc...]
}

and changing the template with d.myArray[i]

I managed to make it work like the example, but if you add another column to the data it does not get rendered...

@chrisdlim
Copy link

I had it working with this :

{d.title[i].text} {d.title[i+1].text}
{d.content[i].content[i].text} {d.content[i].content[i+1].text}
{d.content[i+1].content[i].text} {d.content[i+1].content[i+1].text}

{
  title: [{text: 'Salutation'}, {text: 'lang'}],
  content: [
    {content: [{text: 'Hello'}, {text: 'en'}]},
    {content: [{text: 'Bonjour'}, {text: 'fr'}]}
  ]
}

I never use a direct value from an array. Array contains Object which contains the value to use.

For the doc example, try by using something like that :

{
  myArray : [{"brand": etc...}, {"brand": etc...]
}

and changing the template with d.myArray[i]

Correct me if i'm wrong but..that example isn't using bi-directional looping is it? Isn't this just iterating 2 different arrays, one array in the header cells and one array for the data cells?

@officeutils
Copy link

officeutils commented Aug 26, 2021

This feature does not work at all. For .docx files too. Remove it from your documentation. You stole a lot of my time folks.
Only 2 years have passed since the error was detected

@steevepay
Copy link
Member

Hello @officeutils, thank you for reaching us.

The bi-directional loop depends significantly on the XML coming from the document. If a table is badly formed, Carbone will have difficulty in recognizing the elements to be repeated. Nevertheless, we will address the issue in the next few days to fully manage the recognition and creation of repeatable fields.

Could you please share your template and a JSON dataset without confidential information at "support@carbone.io"? Include on the template the strict minimum to reproduce the issue. We will use it in our testing.

@officeutils
Copy link

@steevepay I sent the all info to support. Thank you very much.

@officeutils
Copy link

@steevepay Is there any update here?

@steevepay
Copy link
Member

Hello @officeutils, we need more time to solve bi-directional loops and it can't be solved in the coming sprints. We will share updates on the feed as soon as we work on it.

@samirotiv
Copy link

Spent two hours trying to get it to work and then found this thread. Any update on this or any workarounds?

@officeutils
Copy link

@samirotiv I found a temporary solution for my problem. I need to create multiple tables with 2-4 columns. Look at the attached picture.
image

@dvernole
Copy link

Any news about this issue?

@enariavishenda
Copy link

delete from the main documentation, misled me, spent half a day

@dgrelaud
Copy link
Member

dgrelaud commented Mar 15, 2023

Carbone v4.8.0 fixes lot of issues for bidirectional loop in DOCX templates.

The website has been updated: https://carbone.io/documentation.html#bi-directionnal-loop

Here is a real life example:

We keep this issue opened.
When Carbone v5 will be available. This repository will be updated with Carbone v4 and we will close this issue.

Feel free to contact us on the chat of the website if you need further help & information.

https://carbone.io/examples/bidirectional-loop/bidirectional-loop.zip

capture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P: High S: approved The issue has been validated. T: bug Functionality that does not work as intended/expected
Projects
None yet
Development

No branches or pull requests