meteor-editable-text
meteor-editable-text copied to clipboard
Use a ReactiveVar instead of a Collection
Greetings!
I have the following HTML template:
<template name="type_create">
<form>
<p class="editable-text-trigger">
<strong>Title: </strong>
{{> editableText context=data field="title" textarea=false removeEmpty=false wysiwyg=false allowEmpty=false}}
</p>
<p class="editable-text-trigger">
<strong>Description: </strong>
{{> editableText context=data field="description" textarea=true removeEmpty=false wysiwyg=true allowEmpty=false}}
</p>
<p>
<button type="submit">Create Type</button>
</p>
</form>
</template>
and no JS file.
I initialize the template view in the following way:
var view = Blaze.renderWithData(Template['type_create'],
function() { return new ReactiveVar({ title: "aa", description: "bb" }); }, modal.body[0]);
When I try to update one of the text inputs, I see the following error in the console:
Exception while simulating the effect of invoking '_editableTextWrite' errorClass {message: "Match error: Expected string, got undefined", path: "", sanitizedError: errorClass, errorType: "Match.Error"}errorType: "Match.Error"message: "Match error: Expected string, got undefined"path: ""sanitizedError: errorClassstack: (...)get stack: get stack()set stack: set stack()__proto__: Error Error: Match error: Expected string, got undefined
debug.js:43
This package is just for updating fields from documents in collections.
Do you know what can be changed in order to use reactive variables?
You could overwrite the EditableText.update
function on the client and make some tweaks to the editable-text.html
and editable-text.js
files to add new possible parameters when initializing the widget (so it knows which ReactiveVar to target) but, at that stage, it might just be easier to write a dedicated package to deal with ReactiveVar's. Otherwise you end up with a big bunch of code on client and server that never gets used by your app.
I just noticed this, after posting a similar request (you can delete the other request, if you wish).
I was also wondering, what about local collections? Perhaps I could have a single record in a local collection with the fields I want to edit locally? Does that work?
I'm pretty sure this wouldn't work with local collections without overwriting the EditableText.update
function on the client (in which case you wouldn't be able to make fields of documents in your db collections editable anymore). In theory, the package could be extended to include this functionality, but it's unlikely I'll get time to do this anytime soon.
Hm, I'm also suddenly finding a need for this, so that I can reactively change the size of the text depending on its length—unless there's a callback for when the value changes?