Module: Glib::JsonUi::ViewBuilder::Fields::ChangeTrigger

Included in:
Text
Defined in:
app/helpers/glib/json_ui/view_builder/fields.rb

Overview

Timing options for the onChange / onChangeAndLoad actions of fields whose value changes while the user is still typing.

Honoured by the single-line text family (text, number, email, url, password -- all one Vue component) and by textarea. Other fields ignore them: the discrete ones (check, radio, select, chip group, date pickers) commit a value the moment it is picked, and richText/phone/file keep their own reporting. The options are declared on Text, so its other subclasses accept them without effect -- same as leftIcon and onTypeStart there.

In both modes the change is also reported when focus leaves the field. Under input that only flushes a change already pending in the debounce window -- it cannot produce a second run, because a value that was already reported is not reported again.

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 230

def self.included(base)
  # When the `onChange` / `onChangeAndLoad` actions fire.
  #
  # - `input` (default): after the user pauses typing for `changeDelay`.
  # - `blur`: only once focus leaves the field. Use for actions too
  #   expensive to run mid-word -- a server round trip, a recalculation
  #   that rewrites other fields under the user's cursor.
  #
  # @example Round-trip only once the user is done with the field
  #   form.fields_text \
  #     name: 'user[promo_code]',
  #     label: 'Promo code',
  #     changeOn: 'blur',
  #     onChange: ->(action) { action.http_get url: verify_promo_path }
  base.enum :changeOn, options: %w[input blur]

  # Milliseconds of no typing before `changeOn: 'input'` fires.
  # Defaults to 300. Ignored under `changeOn: 'blur'`.
  #
  # @example Slow down a search-as-you-type round trip
  #   form.fields_text \
  #     name: 'q',
  #     label: 'Search',
  #     changeDelay: 800,
  #     onChange: ->(action) { action.http_get url: search_path }
  base.int :changeDelay
end