Add input fields to your extension About Input Fields Input Field Types String Example Number Example SecureValue Example Request Example EnvironmentVariable Example Select Example Checkbox Example Radio Example KeyValueList Example JSON Example Accessing Input Field Values Dynamic Values Example Importers Example Exporters / Code Generators Example Add input fields to your extension¶ Extensions Add input fields to your extension About Input Fields¶ You can let the users of your extension enter inputs that you’ll get the value during the evaluate() (for Dynamic Values) / import() (for Importers) / generate() (for Exporters/Code Generators) call. Each input is represented by an instance of the InputField class. Input Field Types¶ String¶ Allows the input of text data. To create a InputField of String type, you should specify: key: an identifier for the input name: a text to be displayed to the user type = "String" options (optional): persisted: Whether the last value introduced by the user will be remembered (persisted in user defaults). Useful for Importers and Exporters. defaultValue: Default value of the field (when there is no previous persisted value). placeholder: Placeholder string for the field (if there is no default value neither previous persisted value). Example¶ MyExtension.inputs = [ InputField("name", "Name", "String"), InputField("email", "Email", "String", {persisted: true, defaultValue: "Enter Email", placeholder: "Type an email"}), ]; Number¶ Allows the input of numbers, either integer or float. To create a InputField of Number type, you should specify: key: an identifier for the input name: a text to be displayed to the user type = "Number" options (optional): persisted: Whether the last value introduced by the user will be remembered (persisted in user defaults). Useful for Importers and Exporters. defaultValue: Default value of the field (when there is no previous persisted value). placeholder: Placeholder string for the field (if there is no default value neither previous persisted value). float: whether the input number must be a float. minValue: minimum acceptable value. maxValue: maximum acceptable value. Example¶ MyExtension.inputs = [ InputField("phone", "Phone", "Number"), InputField("postal", "Postal Code", "Number", {persisted: true, defaultValue: "Enter Email", placeholder: "Type an email", float: true, minValue: 0, maxValue: 10.5}), ]; SecureValue¶ Allows the input of sensitive data. To create a InputField of SecureValue type, you should specify: key: an identifier for the input name: a text to be displayed to the user type = "SecureValue" options (optional): persisted: Whether the last value introduced by the user will be remembered (persisted in user defaults). Useful for Importers and Exporters. placeholder: Placeholder string for the field (if there is no previous persisted value). Example¶ MyExtension.inputs = [ InputField("pwd", "Password", "SecureValue"), InputField("secret", "Secret", "SecureValue", {placeholder: "Type a secret!"}), ]; Request¶ Allows to select a request from current document. To create a InputField of Request type, you should specify: key: an identifier for the input name: a text to be displayed to the user type = "Request" options (optional): persisted: Whether the last value introduced by the user will be remembered (persisted in user defaults). Useful for Importers and Exporters. Example¶ MyExtension.inputs = [ InputField("req", "Source Request", "Request") ]; EnvironmentVariable¶ Allows to select an environment variable from current document. To create a InputField of EnvironmentVariable type, you should specify: key: an identifier for the input name: a text to be displayed to the user type = "EnvironmentVariable" options (optional): persisted: Whether the last value introduced by the user will be remembered (persisted in user defaults). Useful for Importers and Exporters. Example¶ MyExtension.inputs = [ InputField("var", "Variable", "EnvironmentVariable") ]; Select¶ Allows to select an option from the predefined ones. To create a InputField of Select type, you should specify: key: an identifier for the input name: a text to be displayed to the user type = "Select" options: choices (required): A dictionary mapping choices values <-> display values. persisted (optional): Whether the last value introduced by the user will be remembered (persisted in user defaults). Useful for Importers and Exporters. Example¶ MyExtension.inputs = [ InputField("var", "Checksum", "Select", {"choices": {"md2": "MD2", "md5": "MD5", "sha": "SHA-1"}, persisted: true}) ]; Checkbox¶ Allows to select an option. To create a InputField of Checkbox type, you should specify: key: an identifier for the input name: a text to be displayed to the user type = "Checkbox" options (optional): defaultValue: Default value of the field (true/false). persisted: Whether the last value introduced by the user will be remembered (persisted in user defaults). Useful for Importers and Exporters. Example¶ MyExtension.inputs = [ InputField("chk1", "Export Everything", "Checkbox", {defaultValue: true}) ]; Radio¶ Allows to select one from multiple options. To create a InputField of Radio type, you should specify: key: an identifier for the input name: a text to be displayed to the user type = "Radio" options: choices (required): A dictionary mapping choices values <-> display values. persisted (optional): Whether the last value introduced by the user will be remembered (persisted in user defaults). Useful for Importers and Exporters. defaultValue (optional): Default value of the field. Example¶ MyExtension.inputs = [ InputField("format", "Format", "Radio", {"choices":{"radio-json":"JSON", "radio-yaml":"YAML"}, defaultValue: "radio-yaml"}) ]; KeyValueList¶ Allows the input of multiple key-value pairs. To create a InputField of KeyValueList type, you should specify: key: an identifier for the input name: a text to be displayed to the user type = "KeyValueList" options (optional): keyName: Header name for the key column. valueName: Header name for the value column. persisted: Whether the last value introduced by the user will be remembered (persisted in user defaults). Useful for Importers and Exporters. defaultValue: Default values of the field. Example¶ MyExtension.inputs = [ InputField("kvl", "Headers", "KeyValueList", {"keyName":"Header", "valueName":"Value", defaultValue: '[["Accept", "text/*", 1], ["Allow", "GET, POST", 0]]'}) ]; JSON¶ Allows the input of JSON data. To create a InputField of JSON type, you should specify: key: an identifier for the input name: a text to be displayed to the user type = "JSON" options (optional): persisted: Whether the last value introduced by the user will be remembered (persisted in user defaults). Useful for Importers and Exporters. defaultValue: Default values of the field. Example¶ MyExtension.inputs = [ InputField("json", "JSON", "JSON", {defaultValue: '{"k1": "v1", "t1": {"tk1": "tk1"}, "k2": 426}'}) ]; Accessing Input Field Values¶ Dynamic Values¶ For Dynamic Values, input values are accessible through the specified key as a javascript variable. Example¶ var MyDynamicValue = function() { this.evaluate = function(context) { return this.phone; } } MyDynamicValue.inputs = [ InputField("phone", "Phone", "Number") ]; Importers¶ For Importers, input values are accessible through the options.inputs argument from the import() function. Example¶ var MyImporter = function() { this.import = function(context, items, options) { console.log("My phone is " + options.inputs['phone']); return true; } } MyImporter.inputs = [ InputField("phone", "Phone", "Number") ]; Exporters / Code Generators¶ For Exporters/Code Generators, input values are accessible through the options.inputs argument from the generate() function. Example¶ var MyExporter = function() { this.generate = function(context, requests, options) { return "Generated phone is " + options.inputs['phone']; } } MyExporter.inputs = [ InputField("phone", "Phone", "Number") ];