Spell checking using the Web browser control

More
1 year 11 months ago #426 by James Levin
James Levin created the code: Spell checking using the Web browser control
Spell checking using the Webbrowser control. This sample code is from NYSDOH.
This code sets up a basic HTML page with a text area with spellchecking.

We placed the new web browser control on a response window with this basic logic and now we have spellchecking within our application..
This includes the key code to make this work.
We hope this is helpful.

Create u_webbrowser_spellcheck from webbrowser (do not set the default url. )
Create variables
Private:
boolean ib_initialized = False
String is_text, is_text_html
long il_max_length

private function boolean of_set_text ();
boolean success = True
String ls_Result, ls_Error
// Text area with spell check for text area – use set focus to immediate show the spelling issues
String ls_pre_html = '<textarea id="text" spellcheck="true" rows="10" cols="80" autofocus'
String ls_pre_html_len = ''
String ls_pre_html_end = '>'
String ls_post_html = '</textarea>'
String ls_html

if il_max_length > 0 then
ls_pre_html_len = ' maxlength="' + string(il_max_length) + '" '
end if

ls_html = ls_pre_html + ls_pre_html_len + ls_pre_html_end + is_text_html + ls_post_html

this.Evaluatejavascriptsync("document.body.innerHTML = ' " + ls_html + " ' ", ls_Result, ls_Error)

if (ls_Error <> "") then
success = false
log error
End if


return success

end function

public function string of_get_text ();
String ls_java_script, ls_Result, ls_Error, ls_new_result
long ll_pos

ls_java_script = 'document.getElementById("text").value;'
this.Evaluatejavascriptsync(ls_java_script, ls_Result, ls_Error)

If ls_Error> "" then
messagebox("JavaScript error", "ls_Error=" + ls_Error)
else
// ls_Result -- has the following {"type":"string","value":"test this out"}
ll_pos = len('{"type":"string","value":"') + 1
ls_new_result = mid (ls_Result, ll_pos , len (ls_Result) - (ll_pos +1))
ls_new_result = Object function .of_javasciprt_returned_string(ls_new_result)
=================================
Function to.. update javascript returned string with characters to acceptable for PB
javascript uses the backslash as their escape character
ret_val = f_string_replace_all (ret_val, '\"', '"') // double quote
ret_val = f_string_replace_all (ret_val, '\\', '\') // backslash
ret_val = f_string_replace_all (ret_val, '\n', char(13) + char(10)) // newline
ret_val = f_string_replace_all (ret_val, '\t', char(9)) // tab
=================================
End if

return ls_new_result

end function

public function boolean of_set_text (string text, long max_length);
boolean success = True

is_text = text
is_text_html = object function .. of_html_string(is_text)
=================================
Function to.. update PB string with characters to acceptable for html and Javascript
ret_val = f_string_replace_all (ret_val, "&", "&") // ampersand
ret_val = f_string_replace_all (ret_val, '"', """) // double quote
ret_val = f_string_replace_all (ret_val, "'", "'") // apostrophe
ret_val = f_string_replace_all (ret_val, "~r~n", " ") // new line
ret_val = f_string_replace_all (ret_val,char(13) + char(10) , " ") // new line
ret_val = f_string_replace_all (ret_val, "~t", " ") // tab
ret_val = f_string_replace_all (ret_val, char(9) , " ") // tab
ret_val = f_string_replace_all (ret_val,'/' , "/") // slash
ret_val = f_string_replace_all (ret_val,'\' , "\") // backslash
========================================
il_max_length = max_length
// it’s key to make sure the browser has completely initialize before setting the html
if ib_initialized then success = of_set_text()
return success

end function

public function boolean of_get_initialized ();Return ib_initialized
end function

event navigationstatechanged;
if not ib_initialized then
ib_initialized = true //this is key ….once the web browser control ready then call set text
of_set_text()
end if

end event


On our App Manager object – create a function to open spell check
public function boolean uf_open_spellcheck (datawindow adw, long row, string column_name, string column_label, ref string as_updated_text);
]//Spellcheck
// Success result will be
// TRUE = when the column has is updated successfully
// The calling routines can extended as need for their own item change logic
// as_updated_text will contain the updated text
//
// False = No change or Error
boolean success = true
boolean lb_user_cancelled = False
String ls_note, ls_note_limit

If adw.accepttext() < 1 then Return false

ls_note = adw.getitemstring(row,column_name)
ls_note_limit= adw.Describe(column_name + ".Edit.Limit")

success = open spellcheck response window with text, limit and label
 This response window contains u_webbrowser_spellcheck, OK and Cancel button
 Returns true if user clicks ok and the is_updated_text
 In open event .. call settext from _webbrowser_spellcheck with text and max_length

if success then
If ls_note = is_updated_text then lb_user_cancelled = true

IF not lb_user_cancelled then
success = (adw.setitem (row,column_name, is_updated_text) = 1)
if success then
as_updated_text = is_updated_text
//local extension
// call after this routine completes with successs=true
else
- --error handling

end if
end if
end if

if not success then
error handing
end if

if success and lb_user_cancelled then
success = false
End if
return success

end function

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #494 by Christoph Wagner
Christoph Wagner replied the code: Spell checking using the Web browser control
Hi James

Thanks a lot for the quick answer, very much appreciate

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #493 by James Levin
James Levin replied the code: Spell checking using the Web browser control
Based on the documentation for WebBrowserSet I'd look in %temp%\PB220UDF

UserDataFolder -- The folder that stores user data. Both the relative path and absolute path are supported. The default user data folder is %temp%\PB220UDF in the development machine and %temp%\<appname>UDF at the client.

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #492 by Christoph Wagner
Christoph Wagner replied the code: Spell checking using the Web browser control
Hi James

Great idea, a nice and clean solution to implement a simple spell checker. I just wonder if you know where the 'Custom Dictionary' is located for the PB web browser, it's not the desktop Google Chrome Custom Dictionary.

Please Log in or Create an account to join the conversation.

More
6 months 2 days ago #482 by James Levin
James Levin replied the code: Spell checking using the Web browser control
Here's a patch to the code for PB22R2 .. The following changes were made:
1. The default URL of WebBrowser control is empty.
In previous versions, when the default URL is empty, it will open about:blank by default so the Evaluatejavascriptsync function can be executed.
In PB 2022 R2, when the default URL is empty, it will not open any pages, resulting in no Evaluatejavascriptsync function being executed.

Please set the default URL of u_webbrowser_spellcheck to 'about:blank' to solve the issue.

2. Please note that in the WebBrowser event, only the asynchronous function EvaluateJavascriptAsync can be called. You can find this information in the article below.
docs.appeon.com/pb2022r2/pbug/Defining_u..._for_WebBrowser.html

Please move the script below from evet NavigationStateChanged to NavigationCompleted to avoid the application from getting stuck.

if not ib_initialized then
ib_initialized = true
uf_zz_set_text()
end if

Please Log in or Create an account to join the conversation.

More
6 months 2 days ago #481 by James Levin
James Levin replied the code: Spell checking using the Web browser control
Here's a patch to the code for PB22R2 .. The following changes were made:
1. The default URL of WebBrowser control is empty.
In previous versions, when the default URL is empty, it will open about:blank by default so the Evaluatejavascriptsync function can be executed.
In PB 2022 R2, when the default URL is empty, it will not open any pages, resulting in no Evaluatejavascriptsync function being executed.

Please set the default URL of u_webbrowser_spellcheck to 'about:blank' to solve the issue.

2. Please note that in the WebBrowser event, only the asynchronous function EvaluateJavascriptAsync can be called. You can find this information in the article below.
docs.appeon.com/pb2022r2/pbug/Defining_u..._for_WebBrowser.html

Please move the script below from evet NavigationStateChanged to NavigationCompleted to avoid the application from getting stuck.

if not ib_initialized then
ib_initialized = true
uf_zz_set_text()
end if

This message has an attachment file.
Please log in or register to see it.

Please Log in or Create an account to join the conversation.

More
1 year 4 months ago #449 by Miguel Leeuwe
Miguel Leeuwe replied the code: Spell checking using the Web browser control
Fabulous!
Thanks again.

Please Log in or Create an account to join the conversation.

More
1 year 4 months ago #448 by James Levin
James Levin replied the code: Spell checking using the Web browser control
Attached is a code sample. This is a zip file contains pbl created using pb 2021 build 1506.
Hope this helps

This message has an attachment file.
Please log in or register to see it.

Please Log in or Create an account to join the conversation.

More
1 year 4 months ago #447 by Miguel Leeuwe
Miguel Leeuwe replied the code: Spell checking using the Web browser control
Thank you James, that would be great!

Please Log in or Create an account to join the conversation.

More
1 year 4 months ago #446 by James Levin
James Levin replied the code: Spell checking using the Web browser control
Most of the code is with the original post, but let me see what I can do to put together a sample prototype

Please Log in or Create an account to join the conversation.

More
1 year 4 months ago #445 by Miguel Leeuwe
Miguel Leeuwe replied the code: Spell checking using the Web browser control
Hi James,
This seems like a great alternative option to traditional spell checks.
It would be very helpful if you could add a small sample application though.
(I'm still going to try and figure out how to use the pasted code, but when I have some time).

Thank you!
MiguelL

Please Log in or Create an account to join the conversation.

Moderators: Appeon Administrator