fix acroform select field
This commit is contained in:
committed by
Pete Matsyburka
parent
e9034d8da7
commit
0b0f0b497e
@@ -6,6 +6,20 @@ module Templates
|
||||
|
||||
FIELD_NAME_REGEXP = /\A(?=.*\p{L})[\p{L}\d\s-]+\z/
|
||||
SKIP_FIELD_DESCRIPTION = %w[undefined].freeze
|
||||
SELECT_PLACEHOLDER_REGEXP = /\b(
|
||||
Select |
|
||||
Choose |
|
||||
Wählen |
|
||||
Auswählen |
|
||||
Sélectionner|
|
||||
Choisir |
|
||||
Seleccionar |
|
||||
Elegir |
|
||||
Seleziona |
|
||||
Scegliere |
|
||||
Selecionar |
|
||||
Escolher
|
||||
)\b/ix
|
||||
|
||||
module_function
|
||||
|
||||
@@ -143,8 +157,8 @@ module Templates
|
||||
{
|
||||
**attrs,
|
||||
type: 'select',
|
||||
options: build_options(field[:Opt]),
|
||||
default_value: field.field_value
|
||||
options: build_options(field[:Opt], 'select'),
|
||||
default_value: field.field_value.to_s.match?(SELECT_PLACEHOLDER_REGEXP) ? nil : field.field_value
|
||||
}
|
||||
elsif field.field_type == :Ch && field.concrete_field_type == :multi_select && field[:Opt].present?
|
||||
{
|
||||
@@ -178,11 +192,14 @@ module Templates
|
||||
def build_options(values, type = nil)
|
||||
is_skip_single_value = type.in?(%w[radio multiple]) && values.uniq.size == 1
|
||||
|
||||
values.map do |option|
|
||||
values.filter_map do |option|
|
||||
is_option_number = option.is_a?(Symbol) && option.to_s.match?(/\A\d+\z/)
|
||||
|
||||
option = option[1] if option.is_a?(Array) && option.size == 2
|
||||
option = option.encode('utf-8', invalid: :replace, undef: :replace, replace: '') if option.is_a?(String)
|
||||
|
||||
next if type == 'select' && option.to_s.match?(SELECT_PLACEHOLDER_REGEXP)
|
||||
|
||||
{
|
||||
uuid: SecureRandom.uuid,
|
||||
value: is_option_number || is_skip_single_value ? '' : option
|
||||
|
||||
@@ -122,6 +122,15 @@ module Templates
|
||||
|
||||
io = StringIO.new
|
||||
|
||||
pdf.acro_form.each_field do |field|
|
||||
next if field.field_type != :Ch ||
|
||||
field[:Opt].blank? ||
|
||||
%i[combo_box editable_combo_box].exclude?(field.concrete_field_type) ||
|
||||
!field.field_value.to_s.match?(FindAcroFields::SELECT_PLACEHOLDER_REGEXP)
|
||||
|
||||
field[:V] = ''
|
||||
end
|
||||
|
||||
pdf.acro_form.create_appearances(force: true) if pdf.acro_form[:NeedAppearances]
|
||||
pdf.acro_form.flatten
|
||||
|
||||
|
||||
Reference in New Issue
Block a user