Skip to content

Commit

Permalink
feat: set data field if fieldName is passed to TextEditorWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Oct 9, 2023
1 parent 872f91e commit f1774ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const SimpleTextEditorWidget = (props) => {
setSelected,
onSelectBlock,
onChangeBlock,
fieldName,
block,
value,
selected,
Expand Down Expand Up @@ -66,8 +67,9 @@ const SimpleTextEditorWidget = (props) => {

useEffect(() => {
//inizializzazione del valore nel campo
if (fieldRef.current && value?.length > 0) {
fieldRef.current.innerText = value;
const _value = value ?? data[fieldName];
if (fieldRef.current && _value?.length > 0) {
fieldRef.current.innerText = _value;
}
}, []);

Expand All @@ -82,7 +84,13 @@ const SimpleTextEditorWidget = (props) => {
tabIndex={0}
placeholder={placeholder || intl.formatMessage(messages.text)}
onInput={(e) => {
onChangeBlock(block, { ...data, value: e.target.textContent });
let retVal = {
value,
};
if (fieldName) {
retVal = { [fieldName]: value };
}
onChangeBlock(block, { ...data, ...retVal });
}}
onFocus={(e) => {
if (!selected) {
Expand Down
10 changes: 8 additions & 2 deletions src/components/ItaliaTheme/manage/Widgets/TextEditorWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,16 @@ const TextEditorWidget = (props) => {
}
}}
onChange={(value, selection, editor) => {
onChangeBlock(block, {
...data,
let retVal = {
value,
plaintext: serializeNodesToText(value || []),
};
if (fieldName) {
retVal = { [fieldName]: value };
}
onChangeBlock(block, {
...data,
...retVal,
// TODO: also add html serialized value
});
}}
Expand Down

0 comments on commit f1774ca

Please sign in to comment.