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

initialValue block setting doesn't work #5971

Open
wesleybl opened this issue Apr 22, 2024 · 3 comments · May be fixed by #5978
Open

initialValue block setting doesn't work #5971

wesleybl opened this issue Apr 22, 2024 · 3 comments · May be fixed by #5978
Labels
01 type: bug 30 needs: triage New issue that needs confirmation before work begins

Comments

@wesleybl
Copy link
Member

Describe the bug
initialValue block setting doesn't work.

To Reproduce
Steps to reproduce the behavior:

  1. Create a block with the initialValue setting. For example:
function initialValue({ id, value, formData, intl }) {
  return {
    ...formData.blocks[id],
    myField: 'test',
  };
}
const applyConfig = (config) => {
  config.blocks.blocksConfig.myBlock = {
    id: 'myBlock',
    initialValue: initialValue,
    ...
  };
  return config;
};
  1. Add the block to a page
  2. The myField field is not filled with the value 'test'.

Expected behavior
The myField field should be filled with the value 'test'.

Software (please complete the following information):

Volto 18.0.0-alpha.27
Plone 6.0.10
plone.restapi 9.5.0

Additional context
The configuration does not work because the block id that is passed to the _applyBlockInitialValue function is the id of the previous block, and not the id of the newly created block. See:

The id passed there should be newBlockId and not id.

Even making this fix, one thing that still happens is that when the previous one is a block of text, the setting is not applied. The insertBlock method is not called in this situation. I wouldn't know where to call _applyBlockInitialValue in this situation. I know that the changeBlock method is called in this situation. But I don't know if it would be the right place, since it is called several times.

@wesleybl wesleybl added 01 type: bug 30 needs: triage New issue that needs confirmation before work begins labels Apr 22, 2024
@wesleybl
Copy link
Member Author

@tiberiuichim any tips on how to make this work if the previous block is a text block?

@wesleybl
Copy link
Member Author

In fact, insertBlock is not called if the previous block is an empty text block. If the text block is not empty, insertBlock is called.
The difference between adding a block after any block and after a empty text block is here:

onInsertBlock={(id, value) => {
if (blockHasValue(data)) {
onSelectBlock(onInsertBlock(id, value));
} else {
onChangeBlock(id, value);
}
}}

When the previous block is an empty text block, if returns false and then onChangeBlock is called. In other situations onSelectBlock is called.

Maybe _applyBlockInitialValue has to be called before calling onChangeBlock.

@tiberiuichim
Copy link
Contributor

The id passed there should be newBlockId and not id.

You are correct here

@wesleybl wesleybl linked a pull request Apr 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
01 type: bug 30 needs: triage New issue that needs confirmation before work begins
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants