jComponent icon indicating copy to clipboard operation
jComponent copied to clipboard

Access UI element values within a Plugin?

Open DPain opened this issue 6 years ago • 5 comments

Hi, I created a Plugin with text fields. This Plugin sends a websocket to the webserver that then sends http requests to a different endpoint. I got all the websocket and http request call code working, so that's not a problem. I just can't seem to access the values of the UI elements in the Plugin.

I checked https://wiki.totaljs.com/jcomponent/07-plugins and saw that I can WATCH when the values change, but I just need the values when I click a button.


Example accessing text value within a component in Flow UI. Component name: test Element name: name

GET("settings.test.name");


I'm trying not to use the anonymous scopes, so my question is what path should I access to get values of UI elements' values in a plugin using the GET method.

DPain avatar Aug 24 '20 20:08 DPain

Can you show the html you have? What do you mean by "text field", is it textbox or input component??

molda avatar Aug 25 '20 06:08 molda

In the current case, it's a J-Input, but I might use different types of jComponents like jCodemirror.

Code: https://pastebin.com/WQLktFyB

DPain avatar Aug 25 '20 08:08 DPain

Receiving server response via Event Listener works well. I just need to know how to modify the j-input and j-codemirror values via the SET() method in the example.

DPain avatar Aug 25 '20 13:08 DPain

For this <div data---="input__comment__type:string">Comments</div> simple GET('comment') should work. BUT i would strongly recomend to have an object for the form, something like requestform and use it like this

<div data---="modal__common.form__if:request;submit:request/submit;title:Confirmation Window" class="hidden">
...
    <div data---="input__requestform.comment__type:string">Comments</div>
...
...
    <div data---="codemirror__requestform.response__type:json;height:150;">response from server goes here.</div>
</div>
 
<script>
    PLUGIN('request', function (exports) {
        exports.submit = function () {
            // get the form data
            var form = GET('requestform');


            // set the response to the form
            SET('requestform.response', <response>);

molda avatar Aug 25 '20 14:08 molda

I should've tried this haha I thought the values would be accessible in some other location for some reason.

Thanks!

DPain avatar Aug 25 '20 14:08 DPain