Triggering state change
I'm trying to create a custom component that's a block editor, using the Laraberg library (https://github.com/VanOns/laraberg). The laraberg editor gets initialized from a textfield, this textfields value is then updated on submit. The value does get updated, but it doesn't seem to update the state, meaning null gets sent to the backend.
This is the code for the component I have right now.
12 Replies
If you inspect the textarea in the browser, does it contain the correct content?
It does, when I submit it flashes there, and if I instead of creating a record dd. So it doesn't go further I can also see it.
If I try submitting again after that it's still null, but if I type a letter into the textarea (that still has the content), it then gets saved when I click submit again.
This is the reason i'm thinking something is not triggering the state change.
and if I instead of creating a record ddWhere did you try
dd()
?In
handleRecordCreation
And you can see the data from the textarea, in the output of dd?
no the data for the textarea is always null. Until I manually type in it.
Hmm... I'm thinking the issue is with
x-model
maybe?
Do you have any other way of getting the state of the Laraberg editor in JS?
Something like an event listener, where you could manually update this.state
Not as far as I know. And the source for the js doesn't seem to be public, only the minified version.
I don't have any experience with this package unfortunately, but I'm thinking the first step would be to verify that you are getting the data from the editor in
state
. What if you setup an Alpine watcher ($watch()
) and console.log()
the state when it changes?Did you mean to watch the state? If I do that I can confirm that it only updates the state when I manually type in the textbox. Not when Laraberg changes it.
Ok, so that's the issue. Not sure why but it seems like
x-model
will not work in this context
I think this is the JS part of the package : https://github.com/VanOns/block-editor
Maybe there's a hook in there where you can listen for internal state changes from the editor.Thanks I'll try and dive into it.