You are currently viewing the Homey Apps SDK v2 documentation. New apps should use Homey Apps SDK v3 ››

Homey.FlowArgument

const { FlowArgument } = require('homey');

The FlowArgument class represents an argument for a Flow Card as defined in the app's app.json. This class must not be initiated by the developer, but retrieved by calling FlowCard#getArgument.

Table of Contents

Methods

registerAutocompleteListener(fn) → {FlowArgument}

Register a listener for a autocomplete event. Return a Promise, or run the callback. This is fired when the argument is of type autocomplete and the user typed a query.

Parameters:
Name Type Description
fn function
Name Type Description
query string

The typed query by the user

args Object

The current state of the arguments, as selected by the user in the front-end

callback function
Name Type Description
err Error
result Array

An array of result objects

Returns:
Type:
FlowArgument
Example
const Homey = require('homey');

let myAction = new Homey.FlowCardAction('my_action');
myAction.register();

let myActionMyArg = myAction.getArgument('my_arg');
myActionMyArg.registerAutocompleteListener( ( query, args ) => {
  let results = [
    {
      "id": "abcd",
      "name": "My Value"
    }
  ];

  // filter for query
  results = results.filter( result => {
    return result.label.toLowerCase().indexOf( query.toLowerCase() ) > -1;
  });

  return Promise.resolve( results );
});