[Gambas-user] Copying large string from javascript procedure

Bruce Steers bsteers4 at gmail.com
Thu Jul 21 00:01:40 CEST 2022


On Wed, 20 Jul 2022 at 17:05, Safiur Rahman <isafiur at gmail.com> wrote:

> The project is attached here
>
> On Wed, Jul 20, 2022 at 9:42 PM Safiur Rahman <isafiur at gmail.com> wrote:
>
>> Hi
>>
>> Is there a way to copy large string from javascript function (in
>> gb.web.gui) so that it can be used elsewhere.
>>
>> Currently only few controls (eg. WebTextBox) can be filled from
>> javascript procedure. However, WebTextBox is not able to hold large
>> data (eg. from image).
>>
>> Case:1 (works fine)
>>
>> Public Sub WebButton5_Click()
>>
>>   WebForm._AddJavascript("var xdata = 'abcdef'")
>>   WebForm._AddJavascript("$_(" & JS(WebTextBox1.Name & ":entry") &
>> ").value = xdata")
>>   WebForm._AddJavascript("gw.update(" & JS(WebTextBox1.Name) & ",
>> 'text', xdata);")
>>
>> End
>> -> string shown in WebTextBox
>>
>>
>> Public Sub WebButton4_Click()
>>
>>   WebHtml1.Html = WebTextBox1.Text
>>
>> End
>> -> "abcdef" is displayed in WebHtml
>>
>>
>>
>> Case:2 (doesn't work fine)
>>
>> Public Sub _new()
>>
>>   Me.AddJavascriptFile("js/sketchpad.js")
>>   ''https://github.com/tsand/responsive-sketchpad
>>
>> End
>>
>> Public Sub WebContainer1_Render()
>>
>>   WebForm._AddJavascript("var pad = new Sketchpad($_(" &
>> JS(WebContainer1.Name) & "), { line: {color: '#f44335', size: 1}});")
>>
>> End
>>
>>
>> -> Now I draw on the screen
>>
>>
>> Public Sub WebButton1_Click()
>>
>>   WebForm._AddJavascript("var xdata =
>> pad.canvas.toDataURL(\"image/png\")")
>>   WebForm._AddJavascript("$_(" & JS(WebTextBox1.Name & ":entry") &
>> ").value = xdata")
>>   WebForm._AddJavascript("gw.update(" & JS(WebTextBox1.Name) & ",
>> 'text', xdata);")
>>
>> End
>> -> Image data string shown in WebTextBox
>>
>>
>> Public Sub WebButton4_Click()
>>
>>   WebHtml1.Html = WebTextBox1.Text
>>
>> End
>> -> image data string is not shown in WebHtml
>>
>> Question: Is there any way to show the image data string to any
>> WebControl which can be copied and used elsewhere in other procedures?
>>
>> (Attached a project to reproduce the problem. Please rename
>> js/sketchpad.txt to js/sketchpad.js)
>>
>> --
>> Regards
>> Safiur Rahman
>>
>
>
I'm new to GB.web but I'm thinking it's going to be limited with
communication in some ways. So some workarounds will need figuring out

My initial thoughts are going to need to use timers/webtimers a lot to
initiate things one side then let event handlers finish or page refresh/etc
before moving on.

And possibly a better solution to many things could be to save a file on
the server and then read it back rather than try to use the web controls?
Not yet looked into cookies but maybe another possible route?

Sorry I can't help more. (Or help at all yet)

BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220720/4accb07b/attachment-0001.htm>


More information about the User mailing list