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

fix: textarea value not saved/rendered #390

Merged
merged 1 commit into from
Dec 30, 2024
Merged

Conversation

kevinchappell
Copy link
Collaborator

resolves #388

// actions here will be applied to the preview in the editor
action: {
input: function ({ target: { value } }) {
this.setData?.('value', value)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be the Field instance when called from editor preview

@@ -379,7 +375,14 @@ export class Controls {
this.container = container
this.groupOrder = unique(groupOrder.concat(['common', 'html', 'layout']))
this.options = options
return Promise.all(this.registerControls([...defaultElements, ...elements]))

const layoutControls = await import('./layout/index.js')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using dynamic import to prevent circular dependency found when writing tests for controls

@@ -130,13 +130,15 @@ export default class Field extends Component {
}
}

setData = (path, value) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shortcut for setting data without updating the preview or edit panels

@@ -310,7 +312,10 @@ export default class Field extends Component {
const prevData = clone(this.data)
const { action = {} } = controls.get(prevData.config.controlId)
prevData.id = `prev-${this.id}`
prevData.action = action
prevData.action = Object.entries(action).reduce((acc, [key, value]) => {
acc[key] = value.bind(this)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this one but it binds the Field instance so we have access to setData from the component class.

@kevinchappell kevinchappell merged commit 80e0e8a into master Dec 30, 2024
1 check passed
@kevinchappell kevinchappell deleted the fix/input-val-render branch December 30, 2024 06:07
@kevinchappell
Copy link
Collaborator Author

🎉 This PR is included in version 3.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@JordanGarciaDev
Copy link

image

You changed the logic and the meaning of the textarea as the rest of the inputs are created

The value was already being stored like the other inputs, the problem was that when the form was rendered it didn't grab the value of the attrs

Now all the logic changes, and you have to add a lot more code to just condition the textarea, the idea was that just as it renders the input text, email, etc

it would also grab the value from the attrs array, and not leave it aside.

In other words, it was going to take the value of attrs and not create another value outside of attrs

@kevinchappell
Copy link
Collaborator Author

i see what you mean. will take another look

@kevinchappell
Copy link
Collaborator Author

kevinchappell commented Dec 30, 2024

textarea doesn't take a value attribute the same way as a standard input tag. i can add additional logic to dom.create to work around this but I think the better option is logic on the control class as it was implemented.
textarea MDN image

essentially, the HTMLTextAreaElement has a setter that allows textarea.value = 'whatever' to set the innerText of the element which is why the current implementation works. Is the current implementation not working? I only made changes to the textarea control class, you should not need to provide any additional configuration for the textarea to function as expected. Is there an issue storing the value at the root of the element data?

@kevinchappell
Copy link
Collaborator Author

kevinchappell commented Dec 30, 2024

i removed the custom input handler on the textarea class in favor of the built-in preview handler on the Field class. this still uses a root level assignment of content instead of value as value is not a valid attribute of textarea and making it work like input would be a workaround in itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

textarea value not rendered
2 participants