User Tools

Site Tools


action:Custom_HTML_Prompt

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
action:Custom_HTML_Prompt [2016/04/27 04:13]
peternlewis [Using Keyboard Maestro Variables in the HTML Form]
action:Custom_HTML_Prompt [2017/05/10 21:46]
peternlewis Form Validation
Line 35: Line 35:
 | data-kmwindowid | an ID that can be used with the [Execute a JavaScript in Custom Prompt](https://​wiki.keyboardmaestro.com/​action/​Execute_a_JavaScript_in_Custom_Prompt) action | | data-kmwindowid | an ID that can be used with the [Execute a JavaScript in Custom Prompt](https://​wiki.keyboardmaestro.com/​action/​Execute_a_JavaScript_in_Custom_Prompt) action |
  
-For example:\\+For example:
 ```html ```html
 <body data-kmwindow="​SCREEN(Main,​Left,​20%),​SCREEN(Main,​Top,​20%),​420,​560">​ <body data-kmwindow="​SCREEN(Main,​Left,​20%),​SCREEN(Main,​Top,​20%),​420,​560">​
Line 49: Line 49:
 Alternatively you can implement the JavaScript function KMWindow() which returns either a window size (width,​height) or window rectangle (left,​top,​width,​height) as a string. ​ Keyboard Maestro will evaluate any calculations you include. Alternatively you can implement the JavaScript function KMWindow() which returns either a window size (width,​height) or window rectangle (left,​top,​width,​height) as a string. ​ Keyboard Maestro will evaluate any calculations you include.
  
 +If you want to be able to inspect your HTML live, you can use the Terminal command:
 +
 +```sh
 +defaults write com.stairways.keyboardmaestro.engine WebKitDeveloperExtras TRUE
 +```
 +
 +Then you can control-click on elements and use Inspect Element and get an inspector window, including a Console tab.
  
 ---- ----
Line 71: Line 78:
 When the HTML prompt/form is initialized,​ Keyboard Maestro will set all of the HTML form fields to the value of the *Keyboard Maestro Variable* prior to display. ​ If the user closes the prompt/form by clicking the **''​OK''​** button or otherwise submitting the form, then the data on the form is saved back to the corresponding *Keyboard Maestro Variable*. ​ If the user clicks **''​Cancel''​**,​ or presses the **''​ESC''​** key, or otherwise not submitting the form, the prompt/form is closed without saving any data. When the HTML prompt/form is initialized,​ Keyboard Maestro will set all of the HTML form fields to the value of the *Keyboard Maestro Variable* prior to display. ​ If the user closes the prompt/form by clicking the **''​OK''​** button or otherwise submitting the form, then the data on the form is saved back to the corresponding *Keyboard Maestro Variable*. ​ If the user clicks **''​Cancel''​**,​ or presses the **''​ESC''​** key, or otherwise not submitting the form, the prompt/form is closed without saving any data.
  
-The *Keyboard Maestro Variable* “//**HTML Result Button**//​” is set to the parameter in the `Submit()` function. ​ For example:\\+Note: Prior to 7.1 autofocus did not work for textarea types. 
 + 
 +The *Keyboard Maestro Variable* “//**HTML Result Button**//​” is set to the parameter in the `Submit()` function. ​ For example:
  
 ```html ```html
Line 86: Line 95:
 You can add one of these HTML attributes to the Form Field: You can add one of these HTML attributes to the Form Field:
 ^Attribute ^ Action ^ ^Attribute ^ Action ^
-|*data-ignoreinit* | avoid having the field set initially|  +|*data-kmignoreinit* | avoid having the field set initially|  
-|*data-ignoresubmit* |avoid saving form field back to the *Keyboard Maestro Variable*| +|*data-kmignoresubmit* |avoid saving form field back to the *Keyboard Maestro Variable*| 
-|*data-ignore* | avoid setting and saving the form field|+|*data-kmignore* | avoid setting and saving the form field|
  
  
Line 95: Line 104:
 ===== Using JavaScript ===== ===== Using JavaScript =====
  
-You may use any JavaScript that you normally could in an HTML page.\\+You may use any JavaScript that you normally could in an HTML page. 
 Keyboard Maestro provides the following built-in JavaScript functions: Keyboard Maestro provides the following built-in JavaScript functions:
  
Line 102: Line 112:
 | KMWindow() | to return the desired size or frame of the window as a string| | KMWindow() | to return the desired size or frame of the window as a string|
 | KMWillShowWindow() | when the window will be shown| | KMWillShowWindow() | when the window will be shown|
 +| KMDidShowWindow() | when the window was just shown (7.1+) |
  
 From within the window, you can call the following functions: From within the window, you can call the following functions:
Line 117: Line 128:
 Prior to version 7.1, using SetVariable to set a value to something other than a string can [corrupt the variable](https://​forum.keyboardmaestro.com/​t/​corrupted-variables-after-custom-html-setvariable-update-i-fixed-it-please-read/​2881). Prior to version 7.1, using SetVariable to set a value to something other than a string can [corrupt the variable](https://​forum.keyboardmaestro.com/​t/​corrupted-variables-after-custom-html-setvariable-update-i-fixed-it-please-read/​2881).
  
 +==== Form Validation ====
 +
 +You can use HTML5’s form validation to automatically validate the fields. ​ Specify their input types (eg "​email"​ or "​url"​ instead of "​text"​),​ as well as other properties like minimum/​maximum numbers and so on, and then instead of simply:
 +
 +    onclick="​window.KeyboardMaestro.Submit('​OK'​)"​
 +
 +do something like:
 +
 +    onclick="​if ( document.getElementById('​myform'​).checkValidity() ) { window.KeyboardMaestro.Submit('​OK'​) } else { document.getElementById('​myform'​).reportValidity() }"
  
 ==== Debugging JavaScript in the Form ==== ==== Debugging JavaScript in the Form ====
  
  
-Please see this forum post:\\ +Please see this forum post [How to Enable JavaScript Console for KM Custom HTML Prompt](https://​forum.keyboardmaestro.com/​t/​javascript-console-in-custom-html-prompt/​2589/​8).
-[How to Enable JavaScript Console for KM Custom HTML Prompt](https://​forum.keyboardmaestro.com/​t/​javascript-console-in-custom-html-prompt/​2589/​8)+
  
 (!) Be aware that the system will not allow Keyboard Maestro Engine to see keys typed in its own windows so the [[trigger:​Typed String | Typed String triggers]] will not work within Keyboard Maestro Engine windows. (!) Be aware that the system will not allow Keyboard Maestro Engine to see keys typed in its own windows so the [[trigger:​Typed String | Typed String triggers]] will not work within Keyboard Maestro Engine windows.
Line 152: Line 171:
 - [[https://​forum.keyboardmaestro.com/​t/​custom-html-result-button-value-when-prompt-is-closed/​3213/​2|Custom HTML Result Button value when prompt is closed]] - [[https://​forum.keyboardmaestro.com/​t/​custom-html-result-button-value-when-prompt-is-closed/​3213/​2|Custom HTML Result Button value when prompt is closed]]
 - [[https://​forum.keyboardmaestro.com/​t/​png-optimizer/​3282|PNG Optimizer]] - [[https://​forum.keyboardmaestro.com/​t/​png-optimizer/​3282|PNG Optimizer]]
-- [[https://www.google.fr/search?q=site:​forum.keyboardmaestro.com+Custom+HTML+Prompt+action|Keyboard Maestro Forum topics about Custom HTML Prompt action]]+- [[https://forum.keyboardmaestro.com/​search?​q=Custom%20HTML%20Prompt%20action|Keyboard Maestro Forum topics about Custom HTML Prompt action]]
  
 ==== External References ==== ==== External References ====
Line 164: Line 183:
  
  
-  * If your favorite Web/HTML editor is not listed here, and you would like to include it, post a request in the [[https://​forum.keyboardmaestro.com/​c/​general|Keyboard Maestro Forum, ​General ​section]].+  * If your favorite Web/HTML editor is not listed here, and you would like to include it, post a request in the [[https://​forum.keyboardmaestro.com/​c/​wiki|Keyboard Maestro Forum, ​Wiki section]]. 
 + 
 +--- 
 + 
 +**Keywords:​* ​ Custom HTML Prompt, User Prompt, HTML, Dialog
action/Custom_HTML_Prompt.txt · Last modified: 2021/12/11 10:14 by peternlewis