GetGadgetItemText does not read changed text from WebGadget

Post bugreports for the Windows version here
flashbob
User
User
Posts: 92
Joined: Sat May 11, 2024 4:04 pm

GetGadgetItemText does not read changed text from WebGadget

Post by flashbob »

If you add/change text inside <div contenteditable> the command GetGadgetItemText(..) does not read changed text. See sample code below ... Behavior is identical under Windows/Mac and can currently only be solved via APIs.

Tested environment: Win7 x64, PB 6.10 LTS / PB 6.04 LTS, Intel Mac OS Sierra

Code: Select all

EnableExplicit
Enumeration FormGadget
  #web_gadget
  #Btn_read_html
EndEnumeration

Define event
Define HtmlCode$= "<html><body>" +
                    "<div contenteditable>" +
                      "Hello World. Add som Text at this point" +
                    "</div>" +
                  "</body></html>"

OpenWindow(0, 0, 0, 600, 400, "Editable HTML Content", 
           #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget)

ButtonGadget(#Btn_read_html, 5, 5, 85, 25, "get html")
WebGadget(#web_gadget, 0, 35, 600, 400, "")
SetGadgetItemText(#web_gadget, #PB_Web_HtmlCode, HtmlCode$)

Repeat
  event = WaitWindowEvent()
  Select event
    Case #PB_Event_Gadget
      Select EventGadget() 
        Case #Btn_read_html : Debug GetGadgetItemText(#web_gadget, #PB_Web_HtmlCode)
      EndSelect
  EndSelect
Until event = #PB_Event_CloseWindow

infratec
Always Here
Always Here
Posts: 7613
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: GetGadgetItemText does not read changed text from WebGadget

Post by infratec »

Hm ...

GetGadgetItemText() is the opposite to SetGadgetItemText(),
if you use in both cases #PB_Web_HtmlCode
Do you agree :?:

So if you set the text with a html text, it is correct if a html text is returned.
Isn't it?

You want more a flag like #PB_Web_Text.
But that's a feature request.
flashbob
User
User
Posts: 92
Joined: Sat May 11, 2024 4:04 pm

Re: GetGadgetItemText does not read changed text from WebGadget

Post by flashbob »

No, I do not really agree ;-)
So if you set the text with a html text, it is correct if a html text is returned.
Isn't it?
That's the point. The returned html text is not the current/changed html code.
Related to the code example the initial html code is:

Code: Select all

 <html><body><div contenteditable>Hello World. Add som Text at this point</div></body></html>
When I run the program and insert the text "My Text", the updated html code should be returned:

Code: Select all

 <html><body><div contenteditable>Hello World. Add som Text at this point My Text</div></body></html>
But he returned code does not correspond to the changed code, the old code is still returned.
There is no sense in providing a command that returns the same html code as in a previously defined string ...
User avatar
mk-soft
Always Here
Always Here
Posts: 6242
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: GetGadgetItemText does not read changed text from WebGadget

Post by mk-soft »

Not a bug,
Nothing changes in the loaded HTML code. It is an edit field. To get to the entered data it is better to use the WebViewGadget and JScript.

Only the document view changes

Code: Select all


Macro CocoaString(NSString)
  PeekS(CocoaMessage(0, NSString, "UTF8String"), -1, #PB_UTF8)
EndMacro

Procedure.s GetDocumentView(Gadget)
  Protected r1.s, obj
  obj = GadgetID(Gadget)
  obj = CocoaMessage(0, obj, "mainFrame")
  obj = CocoaMessage(0, obj, "frameView")
  obj = CocoaMessage(0, obj, "documentView")
  obj = CocoaMessage(0, obj, "string")
  r1 = CocoaString(obj)
  ProcedureReturn r1
EndProcedure

Enumeration FormGadget
  #web_gadget
  #Btn_read_html
EndEnumeration

Define event
Define HtmlCode$= "<html><body>" +
                    "<div contenteditable>" +
                      "Hello World. Add som Text at this point" +
                    "</div>" +
                  "</body></html>"

OpenWindow(0, 0, 0, 600, 400, "Editable HTML Content", 
           #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget)

ButtonGadget(#Btn_read_html, 5, 5, 85, 25, "get html")
WebGadget(#web_gadget, 0, 35, 600, 400, "")
SetGadgetItemText(#web_gadget, #PB_Web_HtmlCode, HtmlCode$)

Repeat
  event = WaitWindowEvent()
  Select event
    Case #PB_Event_Gadget
      Select EventGadget() 
        Case #Btn_read_html
          Debug GetDocumentView(#web_gadget)
          ;Debug GetGadgetItemText(#web_gadget, #PB_Web_HtmlCode)
      EndSelect
  EndSelect
Until event = #PB_Event_CloseWindow

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
r-i-v-e-r
User
User
Posts: 20
Joined: Thu May 09, 2024 5:18 pm

Re: GetGadgetItemText does not read changed text from WebGadget

Post by r-i-v-e-r »

mk-soft wrote: Thu May 16, 2024 12:04 pm Not a bug,
Nothing changes in the loaded HTML code. It is an edit field. To get to the entered data it is better to use the WebViewGadget and JScript.

Only the document view changes
It's like an edit field, but a user mutating contenteditable elements does necessarily change the HTML.

The notion that GetGadgetItemText() must return only the value set by a prior SetGadgetItemText() is at odds with behaviour already exhibited by the WebGadget, where data from #PB_Web_HtmlCode is updated upon page navigation by the user. Similarly, for the EditorGadget, the user may of course mutate (unless #PB_Editor_ReadOnly) a programmatically set value and have changes be reflected with GetGadgetItemText().

Besides debates over semantics and/or precedent, I'd say there is a potential bug here since behaviour is inconsistent with different WebGadget() flags.

Given code like this:

Code: Select all

Define html.s = "<html>" +
                "<body>" + 
                "<div contenteditable>" +
                "Hello World! Edit this content." +
                "</div>" +
                "</body>" +
                "</html>"

OpenWindow(#PB_Any, 0, 0, 600, 400, "Editable HTML Content", #PB_Window_SystemMenu)

Define btnGetHtml = ButtonGadget(#PB_Any, 8, 8, 100, 25, "Get HTML")
Define webEditor = WebGadget(#PB_Any, 0, 41, 600, 359, "")
SetGadgetItemText(webEditor, #PB_Web_HtmlCode, html)

Repeat
  Define event = WaitWindowEvent()
  Select event
    Case #PB_Event_Gadget
      Select EventGadget() 
        Case btnGetHtml : MessageRequester("HTML:", GetGadgetItemText(webEditor, #PB_Web_HtmlCode))
      EndSelect
  EndSelect
Until event = #PB_Event_CloseWindow
You can edit the content in the <div> and it won't be reflected when pressing the "Get HTML" button.

If you now change:

Code: Select all

Define webEditor = WebGadget(#PB_Any, 0, 41, 600, 359, "")
To:

Code: Select all

Define webEditor = WebGadget(#PB_Any, 0, 41, 600, 359, "", #PB_Web_Edge)
Changes to the <div> will be reflected when pressing the "Get HTML" button.

This applies only for Windows of course.

This difference may be deliberate, to avoid breaking existing WebGadget code which predates the Edge backing. If that is the case, hopefully it can be documented, so we know whether or not things should be expected to act this way.
Post Reply