undefined

API Docs for: 5.4.0
Show:

FileInputBrick Class

Module: Bricks
Parent Module: Utils

The FileInputBrick prototype extends SimpleInputBrick. Provides a control to either select a local file or enter its URL. To instantiate, call new on the FileInputBrick prototype.

Imports RAMP Modules:

Util
TmplHelper
Array
Dictionary

Uses RAMP Templates:

templates/bricks_template.json

Methods

clear

() FileInputBrick chainable

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:2646

Clears the Brick by setting inputValue to "" which sets fileValue to null and userEntered to false.

Returns:

FileInputBrick:

itself

disable

(
  • disable
  • force
)
Brick chainable

Disables or re-enables the Brick.

Parameters:

  • disable Boolean

    true to disable; false to enable

  • force Boolean

    if true, disables the brick even if it's frozen

Returns:

Brick:

itself

displayNotice

(
  • notice
  • [noticeTemplate]
)
Brick chainable

Display a (error) notice on the brick.

Parameters:

  • notice Object

    object with notice data to be passed to the template

  • [noticeTemplate] String optional

    notice template name

Returns:

Brick:

itself

getData

(
  • [wrap]
)
Object

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:2698

Returns FileInputBrick's data. Either a file object or a file URL will be returned along with the file name, not both.

Returns an object:

  • {Object} fileValue file object if any was selected
  • {String} fileName derived file name
  • {Boolean} userSelected a flag indicating if the user has selected the file or typed the URL

Parameters:

  • [wrap] Boolean optional

    indicates of the payload should be wrapped with a Brick's id; useful when collection information from several Bricks at once.

Returns:

Object:

A wrapper object around two properties: inputValue and userEntered

isUserEntered

() Boolean

Checks if the input value was entered by the user or not.

Returns:

Boolean:

true if the input value was entered by the user; false, otherwise

isUserSelected

() Boolean

Checks if the file was selected by the user or not.

Returns:

Boolean:

true if the file was selected by the user; false, otherwise

isValid

() Boolean

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:2661

Checks if the FileInputBrick is valid. It's considered valid if the input value is not "" or a file value is not null.

Returns:

Boolean:

true if valid; false if not

new

(
  • id
  • config
)
chainable

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:2531

Initializes the FileInputBrick by generating a specified template and setting defaults. This Brick fires a CHANGE event on every change inside the input field and on every file selected.

Parameters:

  • id String

    specified id of the Brick

  • config Object

    a configuration object for the Brick

    • [header] String optional

      a Brick header

    • [instructions] String optional

      a configuration object for the Brick

    • [required] Array | Object optional

      collection of rules specifying what external conditions must be valid for the Brick to be enabled

    • [isEnabled] Boolean optional

      specifies if the brick is disabled from the start

    • [freezeStates] Array optional

      a set of rules specifying states Brick should be frozen

    • [baseTemplate] String optional

      a base template name to be used

    • [noticeTemplate] String optional

      a notice template name to be used

    • [containerClass] String optional

      a CSS class of the specific brick container

    • [customContainerClass] String optional

      any other optional CSS class to be added to the brick container

    • [template] String optional

      a name of the specific Brick template

    • [label] String optional

      an input field label. Invisible. Defaults to the Brick's header

    • [placeholder] String optional

      a placeholder to be displayed inside the input field

notify

(
  • eventName
  • data
)
Brick private chainable

Notifies a listener of a Brick event.

Parameters:

  • eventName String

    an eventName that should be reported

  • data Object

    a payload object to be passed along with the @event

Returns:

Brick:

itself

on

(
  • eventName
  • listener
)
Brick chainable

Sets a listener on the Brick for a specified eventName.

Parameters:

  • eventName String

    an eventName to listen for

  • listener Function

    a callback function to be called

Returns:

Brick:

itself

setData

(
  • data
)
FileInputBrick chainable

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:2671

Sets SimpleInputBrick's data. First calls setInputValue and calls set data on the Brick prototype. data object may contain:

  • {Object} fileValue a file object
  • {String} inputValue a input value (file URL)
  • {Boolean} userSelected boolean value indicating if the user is the source of the file value
  • {Boolean} userEntered boolean value indicating if the user is the source of the string value

if both fileValue and inputValue are specified, only fileValue is used.

Parameters:

  • data Object

    a wrapper object for the data to be set.

Returns:

FileInputBrick:

itself

setFileValue

(
  • value
  • userSelected
)
FileInputBrick chainable

Sets file value of the Brick. When setting file object, input value is set to "". If value is null, the form is reset.

Parameters:

  • value Object

    the selected file object

  • userSelected Boolean

    boolean value indicating if the user selected the file

Returns:

FileInputBrick:

itself

setInputValue

(
  • value
  • userEntered
)
FileInputBrick chainable

Inherited from SimpleInputBrick but overwritten in src/js/RAMP/Utils/bricks.js:2591

Sets the current value of the input field. In this case it's a file URL. If the URL is set, the returned file object is null.

First calls setFileValue(null, false) to null the file object, then calls the prototype's setInputValue with the same parameters.

Parameters:

  • value String

    string value to be entered into the input field

  • userEntered Boolean

    boolean value indicating if the user is the source of the string value

Returns:

FileInputBrick:

itself

setState

(
  • state
)
SimpleInputBrick chainable

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:1902

Sets the state of the Brick. Depending on the state, update the visual styles of the input field. Then call the Brick prototype setState function.

Parameters:

  • state String

    a name of the state to set

Returns:

Properties

_isFrozen

Boolean private

Indicates if the Brick is frozen and cannot be interacted with.

Default: false

_listeners

Object private

A collection of listeners to be notified of specified Brick events.

Default: {}

baseTemplate

String private

A default base template name.

Default: "default_base_template"

browseFilesContainer

Object private

A browse files container node

containerClass

String private

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:2470

A CSS class of the FileInputBrick container node.

Default: "fileinput-brick-container"

customContainerClass

String private

Any other custom CSS class to be added to the Brick container node.

Default: ""

event

Object

A dictionary of possible Brick events.

Example:

 event: {
     CHANGE: "brick/change"
 }

fileNode

Object private

A node of the file input control.

filePseudoNode

Object private

A node of the styled pseudo file input control that just looks nice and doesn't do anything.

fileValue

Object private

A file object that is selected through FileAPI.

Default: null

freezeStates

Array private

A set of rules specifying states Brick should be frozen.

Default: []

Example:

 [
      Bricks.Brick.state.SUCCESS,
      Bricks.Brick.state.ERROR
  ],

header

String private

A Brick header.

Default: ""

inputValue

String private

A string that is currently entered in the input field

Default: ""

instructions

String private

An instructional text to be displayed.

Default: ""

isEnabled

Boolean

Specifies if the brick is enabled from creation. If false, the Brick is disabled after initialization.

Default: true

label

String private

An input field label. Invisible. Defaults to the Brick's header.

Default: ""

noticeTemplate

String private

A default notice template name.

Default: "default_brick_notice"

placeholder

String private

A placeholder to be displayed inside the input field.

Default: ""

required

Array

A collection of rules specifying what external conditions must be valid for the Brick to be enabled. This is not used directly by the Brick itself, but instead by the external object manipulating a collection of Bricks. Two types of rules possible: "all" and "any". Any additional properties needed can be specified.

Default: null

Example:

 [
      {
          type: "all",
          check: ["serviceType", "serviceURL"]
      }
 ]

state

Object

A dictionary of Brick events.

Example:

state: {
  SUCCESS: "brick/success",
  ERROR: "brick/error",
  DEFAULT: "brick/default"
 }

template

String private

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:2480

A name of the default FileInputBrick template.

Default: "default_fileinput_brick_template"

userEntered

Boolean private

Indicates if the user entered text into the input field or it was entered programmatically

Default: false

userSelected

Boolean private

A flag indicating if the user has selected the file or the file has been selected using some magical means.

Default: false

Events

Bricks.Brick.event.CHANGE

Published whenever a Brick undergoes some change.

Event Payload:

  • data Object

    anything, usually result of calling getData() on the Brick