Binding server connect variable inside Javascript

Thank you very much @patrick and @Hyperbytes!!
This post is very important for all of us !!

2 Likes

Hi @Hyperbytes,
I followed your procedure and it work, passing the Identity to Tawk.to.

I got a strange thing: When user at first time load the page, the widget do not appear. I have to reload the page to make him appear and works properly.

Through the developers tools in Google Chrome I saw that when I load for first time the page it is like the Browser cut the end of the page, while after reloading it works perfectly.

Here the screenshot:

Any idea about this ?

thank you

Roberto

I will have a look tomorrow when I get in office. I don’t actually use Tawk so I am not that familiar with it, I just liked the challenge of making it work so I will have to look at their documentation 're time zones and restrictions. I suppose there is some sense in needing to know them in a world wide application

Thank you very much !

Sorry about delay, i don’t get that error however i think if you add the line into the head section of your page it may resolve the problem

<?php date_default_timezone_set('Europe/Stockholm'); ?>

Obviously changing it to your required timezone.

Thank you very much @Hyperbytes… I will try and let you know!!

Rather than start a new topic (unless you would prefer me to)
I too am struggling with setting a variable inside javascript.

I have a signature drawing in my database (JSON) e.g [{lx:20,ly:34,mx:20,my:34},{lx:21,ly:33,mx:20,my:34},…];

I return that value in serverconnnect and bind it to a variable
<dmx-value id="sig" dmx-bind:value="sig.value"></dmx-value>
If i place the variable on my page it shows the value correctly.

I then have this at the bottom within the body

    <script type="text/javascript">
    $(document).ready(function () {
      $('.sigPad').signaturePad({displayOnly:true}).regenerate(sig);
    });
      </script>

I need to set a variable ‘sig’ to the value of my JSON signature
var sig = [{lx:20,ly:34,mx:20,my:34},{lx:21,ly:33,mx:20,my:34},…];

I’ve tried the suggestions about, but can’t seem to get it to work.
Many thanks in advance.

Mim

I’ve even tried binding the value to a hidden input field and using
var sig = document.getElementById("mysig").value;
But that doesn’t seem to work either.

Use like this syntax

dmx.app.data.serverconnect.data.abc

Thanks for replying @s.alpaslan
If my value is returned with
{{serverconnectheader.data.querysigheader[0].sig}}

what I should the following be?

var sig = dmx.?

var sig={{serverconnectheader.data.querysigheader[0].sig}}

to bind a value to the hidden field go to dynamic attributes->value and select the server connect returned value, no need for variables

The code is probably called to early, the sig data isn’t loaded yet on document ready.

Have a function on the page to set the signature and call it on the done event of your json datasource.

<dmx-json-datasource id="jsonDS1" is="dmx-serverconnect" url="sig.json" ondone="regenerateSig()"></dmx-json-datasource>
<script>
function regenerateSig() {
  $('.sigPad').signaturePad({displayOnly:true}).regenerate(dmx.parse('jsonDS1.data'));
}
</script>
1 Like

Sorry, I’m slightly confused
The sig value is already stored MSSQL database, a server action and app connect serverconnect returns the record with the sig value. (Classic ASP Server Model)

Here is the documentation I’m following to regenerate the JSON formatted value.
https://github.com/thread-pond/signature-pad/blob/gh-pages/documentation.md
If I add
var sig = [{lx:20,ly:34,mx:20,my:34},{lx:21,ly:33,mx:20,my:34},…]; The value in my database it works

I just cant seem to dynamically set var sig to the {{serverconnectheader.data.querysigheader[0].sig}} value

maybe the issue have something to do with app connect loading the value after your script execute

have you tried this?
var sig={{serverconnectheader.data.querysigheader[0].sig}}

Hi @Hyperbytes
Yes I have, should that work within the script tag?
Error: Uncaught SyntaxError: Unexpected token

dmx.app.data.querysigheader[0].sig

Try please

Sorry, didn’t realise you were working within a script tag.
an alternative could be to assign the value to a session variable within server connect as shown in the start of this thread then set it via php I.e.
var sig = <?php echo $_SESSION..........?>