meteor-editable-text icon indicating copy to clipboard operation
meteor-editable-text copied to clipboard

Use a ReactiveVar instead of a Collection

Open echo66 opened this issue 8 years ago • 6 comments

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

echo66 avatar Apr 28 '16 16:04 echo66

This package is just for updating fields from documents in collections.

JackAdams avatar Apr 29 '16 09:04 JackAdams

Do you know what can be changed in order to use reactive variables?

echo66 avatar May 04 '16 18:05 echo66

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.

JackAdams avatar May 07 '16 01:05 JackAdams

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?

dpatte avatar Jun 16 '16 04:06 dpatte

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.

JackAdams avatar Jul 10 '16 12:07 JackAdams

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?

t3db0t avatar Aug 18 '16 20:08 t3db0t