Method: HexaPDF::Type::AcroForm::TextField#set_format_action
- Defined in:
- lib/hexapdf/type/acro_form/text_field.rb
#set_format_action(type, **arguments) ⇒ Object
Sets the specified JavaScript format action on the field’s widgets.
This action is executed when the field value needs to be formatted for rendering in the appearance streams of the associated widgets.
The argument type can be one of the following:
- :number
-
Assumes that the field value is a number and formats it according to the given arguments. See JavaScriptActions.af_number_format_action for details on the arguments.
- :percent
-
Assumes that the field value is a number and formats it as percentage (where 1=100% and 0=0%). See JavaScriptActions.af_percent_format_action for details on the arguments.
- :time
-
Assumes that the field value is a string with a time value and formats it according to the given argument. See JavaScriptActions.af_time_format_action for details on the arguments.
269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/hexapdf/type/acro_form/text_field.rb', line 269 def set_format_action(type, **arguments) action_string = case type when :number then JavaScriptActions.af_number_format_action(**arguments) when :percent then JavaScriptActions.af_percent_format_action(**arguments) when :time then JavaScriptActions.af_time_format_action(**arguments) else raise ArgumentError, "Invalid value for type argument: #{type.inspect}" end self[:AA] ||= {} self[:AA][:F] = {S: :JavaScript, JS: action_string} end |