### Declare OnFMReady Utilities with Object Syntax Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md When declaring OnFMReady utilities like `noLogging`, `respondTo`, and `unmount` before installing OnFMReady, use object syntax. This ensures proper initialization. ```javascript window.OnFMReady = { noLogging: true, respondsTo: { 'New Invoice Line Item': (param) => {} }, unmount: true }; ``` -------------------------------- ### Example JSON Payload from FileMaker Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md This is an example of a JSON-defined properties object that FileMaker might pass to a JavaScript function in response to a script request. ```json { "id": "9C37599C-E64A-434B-90CE-321E00EACF46", "invoiceId": "0C79ACAD-1D17-4387-A35F-DD61CA6D0147", "description": "Enter Expense Description...", "type": "expense", "created": "2021-08-30" } ``` -------------------------------- ### Perform FileMaker Script with JavaScript Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md Call a FileMaker script directly from your JavaScript code using FileMaker.PerformScript(). Ensure this call is made after OnFMReady.js has been installed in your document. ```javascript FileMaker.PerformScript('Get Invoices'); ``` -------------------------------- ### Pre-configure OnFMReady Source: https://context7.com/stephancasas/onfmready.js/llms.txt Declare global configuration options for OnFMReady before loading the script. Options include disabling logging, removing the FileMaker object outside FM context, and setting up mock handlers for testing. ```html ``` -------------------------------- ### Using `window.OnFMReady.respondTo` Source: https://context7.com/stephancasas/onfmready.js/llms.txt The `respondTo` map allows you to define mock handlers for FileMaker scripts. When `FileMaker.PerformScript` is called in a development environment, OnFMReady.js intercepts it and invokes the corresponding handler function defined in `respondTo`. These handlers can then simulate FileMaker's behavior, including calling back into JavaScript via predefined window-level functions. ```APIDOC ## `window.OnFMReady.respondTo` ### Description This object allows you to mock FileMaker's responses to script requests during browser-based development. You map FileMaker script names to handler functions. ### Usage Define the `respondTo` object on the `window` before or after OnFMReady.js loads. Each key in the object should be a FileMaker script name, and its value should be a JavaScript function that accepts the script parameter and an optional `option` argument. ### Example ```javascript window.OnFMReady.respondTo = { 'Script Name 1': (param, option) => { // Handler logic for Script Name 1 // Simulate FileMaker callbacks if necessary // e.g., window.callbackFunction(data); }, 'Script Name 2': (param) => { // Handler logic for Script Name 2 } }; ``` ### Handlers - **`param`** (string) - The parameter passed to `FileMaker.PerformScript`. - **`option`** (any) - An optional second argument passed to `FileMaker.PerformScript`. ### Simulated Callbacks Within a handler, you can simulate FileMaker invoking JavaScript functions by calling functions defined on the `window` object, as shown in the example. ### Example Usage in Context ```javascript // Mocks FileMaker's response to the "New Invoice Line Item" script window.OnFMReady.respondTo['New Invoice Line Item'] = (param) => { const { invoiceId, type } = JSON.parse(param); // ... handler logic ... const payload = { /* ... */ }; // Simulate FileMaker calling back into JavaScript window.acceptNewLineItem(JSON.stringify(payload)); }; // Mocks FileMaker's response to "Get Customer List" window.OnFMReady.respondTo['Get Customer List'] = (param, option) => { const mockCustomers = [/* ... */]; window.renderCustomerList(JSON.stringify(mockCustomers)); }; ``` ``` -------------------------------- ### Simulate FileMaker Script Response with OnFMReady.js Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md Configure `window.OnFMReady.respondTo` to map FileMaker script names to JavaScript functions. These functions receive script parameters and can simulate responses by calling other JavaScript functions, such as `window.acceptNewLineItem`. ```javascript window.OnFMReady.respondTo = { 'New Invoice Line Item': (param) => { const { invoiceId, type } = JSON.parse(param); const description = { expense: 'Enter Expense Description...', product: 'Enter Product Name...' }[type]; const date = new Date(); const payload = { id: Math.random().toString(36).substring(2), invoiceId, description, type, created: `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}` }; window.acceptNewLineItem(JSON.stringify(payload)); } }; ``` -------------------------------- ### Include OnFMReady.js via CDN Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md Include the OnFMReady.js script as the first element in your HTML's head tag. Choose the appropriate version based on browser support requirements. Pinning a version is recommended to prevent breaking changes. ```html ``` -------------------------------- ### Mocking FileMaker Script Responses with `respondTo` Source: https://context7.com/stephancasas/onfmready.js/llms.txt Define mock handlers for FileMaker scripts using the `window.OnFMReady.respondTo` map. These handlers receive script parameters and can invoke JavaScript callbacks, simulating FileMaker's behavior. Ensure the `onfmready.min.js` script is loaded. ```html ``` -------------------------------- ### Include OnFMReady via CDN Source: https://context7.com/stephancasas/onfmready.js/llms.txt Include OnFMReady as the first script in your document head. Use the ES2020 build for modern browsers or the ES5 build for legacy support (FileMaker Pro < 19.3 / Internet Explorer 11). ```html ``` -------------------------------- ### Call FileMaker Scripts with OnFMReady Source: https://context7.com/stephancasas/onfmready.js/llms.txt Call `FileMaker.PerformScript()` or `FileMaker.PerformScriptWithOption()` directly after loading OnFMReady. Calls are automatically queued and executed once the FileMaker object is injected, eliminating the need for manual polling or callbacks. ```html ``` -------------------------------- ### Listen for FileMaker Ready Event Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md Add an event listener to 'window' or 'document' to detect when FileMaker is ready. This is useful for initializing components that depend on FileMaker. ```javascript window.addEventListener('filemaker-ready', () => { console.log('FileMaker is ready!'); }); ``` ```javascript document.addEventListener('filemaker-ready', () => { console.log('FileMaker is ready!'); }); ``` -------------------------------- ### Listen for FileMaker Injection with `filemaker-ready` Event Source: https://context7.com/stephancasas/onfmready.js/llms.txt Use the `filemaker-ready` DOM event, dispatched on `window` and `document` by OnFMReady, to execute code only after the `FileMaker` object has been successfully injected. This ensures safe access to FileMaker functions. ```javascript // Listen on window window.addEventListener('filemaker-ready', () => { console.log('FileMaker object is now available.'); document.getElementById('fm-status').textContent = 'Connected to FileMaker'; }); // Or listen on document — both receive the event document.addEventListener('filemaker-ready', () => { // Safe to use FileMaker directly here — injection is confirmed FileMaker.PerformScript('Log Page Load', window.location.href); }); ``` -------------------------------- ### Mock FileMaker Script Response Function Signature Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md When defining response functions for `window.OnFMReady.respondTo`, the function can accept either the script parameter or both the parameter and an optional option argument. ```javascript { 'Name of FileMaker Script': (param, option = 0) => { // response logic here } } ``` -------------------------------- ### OnFMReady.js Script (IE11 Support) Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md This script provides OnFMReady.js functionality with support for Internet Explorer 11. It includes polyfills for Object.assign and CustomEvent if they are not natively available. ```html ``` -------------------------------- ### Configure `window.OnFMReady.unmount` to Remove FileMaker Object Source: https://context7.com/stephancasas/onfmready.js/llms.txt Set `window.OnFMReady.unmount = true` to ensure `window.FileMaker` is set to `undefined` when running outside the FileMaker context. This prevents accidental access to a fallback stub, useful for web components served in both environments. ```html ``` -------------------------------- ### Log FileMaker Requests When Outside FileMaker Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md By default, requests to 'PerformScript()' or 'PerformScriptWithOption()' are logged to the console when OnFMReady runs outside of FileMaker. This is helpful for debugging. ```javascript {script: "New Invoice Line Item", param: '{invoiceId: "0C79ACAD-1D17-4387-A35F-DD61CA6D0147", type: "expense"}'} ``` -------------------------------- ### Handle `filemaker-expected` Event for Context Detection Source: https://context7.com/stephancasas/onfmready.js/llms.txt Listen for the `filemaker-expected` event to conditionally show or hide FileMaker-specific UI elements based on whether the script is running inside FileMaker Pro/WebDirect or a plain browser. ```html ``` -------------------------------- ### OnFMReady.js Script (No IE11 Support) Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md This script enables OnFMReady.js functionality without support for older Internet Explorer versions. It intercepts calls to the FileMaker object and dispatches custom events. ```html ``` -------------------------------- ### Detect FileMaker Context with 'filemaker-expected' Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md Use the 'filemaker-expected' event to conditionally enable/disable features based on whether the document is accessed within FileMaker. Avoid checking 'window.FileMaker' directly for context. ```javascript document.addEventListener('filemaker-expected', (event) => { if (event.filemaker) { /*--- feature enable/disable logic here ---*/ } }); ``` -------------------------------- ### Disable Dev-Console Logging with `window.OnFMReady.noLogging` Source: https://context7.com/stephancasas/onfmready.js/llms.txt Set `window.OnFMReady.noLogging = true` to suppress the default developer console logging of `FileMaker.PerformScript()` and `FileMaker.PerformScriptWithOption()` calls when running outside FileMaker. This is recommended for production or CI environments. ```html ``` -------------------------------- ### FileMaker Injection Check Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md This is the check FileMaker Pro or WebDirect performs to determine if it should inject the FileMaker object. It highlights the loose type checking used, as it returns if `window.FileMaker` is not strictly `null`. ```javascript if (window.FileMaker != null) return; // see, i told you it was loose type-checking ``` -------------------------------- ### Disable Logging of FileMaker Requests Source: https://github.com/stephancasas/onfmready.js/blob/master/README.md Declare the global variable 'window.OnFMReady.noLogging = true;' to disable the console logging of FileMaker requests when operating outside of FileMaker. ```javascript window.OnFMReady.noLogging = true; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.