'Sending content from TinyMCE to Airtable
I've implemented TinyMCE on an app I've created, and would like to have it submit the textarea's content to Airtable on button click. The thought process is: retrieve the textarea data, pull some basic information about the user and the Airtable table I'd like to write to, and then create a new record. I'm running into trouble getting the function up and running, though; can anyone take a look at the code below and see where I'm going wrong?
For reference, here's what I have so far:
Header
<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/airtable.umd.min.js"></script>
<script src="https://cdn.tiny.cloud/1/myapikeyhere/tinymce/6/tinymce.min.js" referrerpolicy="origin"></script>
<script>
tinymce.init({
selector: '#mytextarea',
branding: false
});
</script>
Body
<textarea id="mytextarea">Start typing here!</textarea><br><br>
<button onclick="sendtoAirtable()" class="button">Create Post</button>
<script src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>
<script>
function sendtoAirTable(){
var data = tinymce.instances.mytextarea.getData();
saveToAirTable(data);
function saveToAirTable(data){
var userId = window['logged_in_user']['airtable_record_id']
var base = new Airtable({apiKey: 'myapikey'}).base('airtablebaseid');
}
base('tablename').create([
{
"fields": {
"Content":data,
"User": [
userId
]
}
}
], function(err, records) {
if (err) {
console.error(err);
return;
}
});
}
</script>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
