Integration
There are two possible ways to implement JS functionality:
-
Directly within the HTML Form Definition in the head section or within HybridForms blocks:
<script></script>
-
Via an external file and linked scriptTag within the Form Definition's header:
<script data-hf-src="[FILENAME].js"></script>
For detailed examples, explore the Forms provided within the FormDefinitions folder of the "formDev" project.
The basic structure of HybridForms JavaScript (file)​
-
Pack JS within an IIFE (Immediately Invoked Function Expression)
(function () {
'use strict'; // forcing browser to strict mode Javascript
// code here
})(); -
Define your WinJS namespace
WinJS.Namespace.define('HFFormdefinition.NamespaceChild', {
// variables, functions and classes
}); -
For browser (e.g. chrome) debbugging purposes, add the following at the end of the file
//# sourceURL=[Name of the js file].js
-
If you are using ESLint and the
no-undef-rule
, add globals at the beginning of the file to prevent ESLint errors/* global $ WinJS Icomedias HybridForms [...] */
Naming convention for namespacing:
- HFFormdefinition.[FORMDEFINITION-TITLE]
- HFFormdefinition.[EXTERNAL-JS-FILENAME]
Define the namespace once within the HTML Form Definition, especially when utilizing external files. Ensure that each Form Definition has a unique namespace to prevent any potential issues.
Full JavaScript example​
- JavaScript
- HTML
/* ESLint no-undef-rule: define globals to prevent ESLint errors */
/* global $ WinJS IcoWinJS kendo HFWinJS HybridForms Icomedias HFFormdefinition */
(function () {
'use strict'; // forcing browser to strict mode JavaScript
WinJS.Namespace.define('HFFormdefinition.BaseHelpers', {
// variables, functions and classes
});
})();
//# sourceURL=[Name of the js file].js
<html>
<head>
[...]
<script data-hf-src="BaseHelpers.js"></script>
</head>
<body>
<script>
WinJS.Namespace.define('HFFormdefinition.BaseHelpers', {});
</script>
[…]
</body>
<html></html>
</html>