Class: Glib::JsonUi::ViewBuilder::Fields::Sign

Inherits:
AbstractField show all
Defined in:
app/helpers/glib/json_ui/view_builder/fields.rb

Overview

Note:

A saved signature is a signed id that cannot be redrawn from the canvas: when a record is re-edited the field pre-populates value with the existing attachment's signed id (the component renders a read-only preview instead of ink). An untouched field therefore re-submits that same signed id, so consumers should treat a same-signed-id re-attach as "no change". Resize it via components_set/logics_set with width/height.

Signature field that lets the user draw a signature on a canvas and upload it as an image via ActiveStorage direct upload.

The form shows a placeholder sized by width/height; tapping it opens a dialog with the drawing canvas, and Confirm uploads the drawing as a PNG to directUploadUrl and submits the resulting signed id under name. The placeholder then shows the signature, and reopening the dialog lets the user edit it. Because the canvas is not in the form, the placeholder can be given the same height as a neighbouring input (e.g. a typed-name alternative) without losing drawing space.

label titles the dialog; placeholder replaces the "Tap to sign" prompt.

With typedName the dialog gains Draw/Type tabs: the user can type their name instead of drawing, and the placeholder then shows the name in a handwriting style (the glib-sign-typed hook carries the font). The typed name is submitted under typedName[:name]; exactly one of the signed id and the typed name is ever non-blank. typedName[:value] pre-populates an existing name.

Examples:

Basic signature field

form.fields_sign \
  name: 'user[signature]',
  label: 'Your signature',
  directUploadUrl: glib_direct_uploads_url,
  width: 320,
  height: 160,
  validation: { required: { message: 'add your signature!' } }

Drawn or typed

form.fields_sign \
  name: 'user[signature]',
  label: 'Your signature',
  typedName: { name: 'user[signature_name]', label: 'Type your full name', placeholder: 'Full name' },
  directUploadUrl: glib_direct_uploads_url,
  width: 320,
  height: 160

Compact signature without validation

form.fields_sign \
  id: 'signature_compact',
  name: 'user[signature_compact]',
  directUploadUrl: glib_direct_uploads_url,
  width: 220,
  height: 100

See Also:

  • Garage examples

Instance Attribute Summary

Attributes inherited from JsonUiElement

#json, #page

Instance Method Summary collapse

Methods inherited from AbstractField

#autoValidate, #context, #created, #default_url_options, #disableDirtyCheck, #existing_attachment_url, #hint, #hint_args, #label, #label_args, #name, #placeholder, #placeholder_args, #prop, #validation, #value

Methods inherited from View

component_name

Methods inherited from JsonUiElement

action, any, array, badgeable, bool, color, component_name, date, date_time, enum, float, hash, icon, #initialize, int, length, menu, panels_builder, #props, required, singleton_array, string, text, url, views

Constructor Details

This class inherits a constructor from Glib::JsonUi::JsonUiElement

Instance Method Details

#determine_value(context, prop) ⇒ Object

Override A stored signature is an attachment -- submit its signed id (mirrors File#determine_value) so re-editing a signed submission pre-fills the field with the existing blob's signed id instead of serializing the whole attachment proxy.



990
991
992
993
994
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 990

def determine_value(context, prop)
  if (value = context.field_value(prop)).attached?
    value.signed_id || ''
  end
end