add field mask
This commit is contained in:
@@ -366,6 +366,8 @@ module Submissions
|
||||
|
||||
value = value.join(', ') if value.is_a?(Array)
|
||||
|
||||
value = TextUtils.mask_value(value) if field.dig('preferences', 'mask').present?
|
||||
|
||||
composer.formatted_text_box([{ text: TextUtils.maybe_rtl_reverse(value.to_s.presence || 'n/a') }],
|
||||
text_align: value.to_s.match?(RTL_REGEXP) ? :right : :left,
|
||||
padding: [0, 0, 10, 0])
|
||||
|
||||
@@ -391,6 +391,8 @@ module Submissions
|
||||
when ->(type) { type == 'cells' && !area['cell_w'].to_f.zero? }
|
||||
cell_width = area['cell_w'] * width
|
||||
|
||||
value = TextUtils.mask_value(value) if field.dig('preferences', 'mask').present?
|
||||
|
||||
chars = TextUtils.maybe_rtl_reverse(value).chars
|
||||
chars = chars.reverse if field.dig('preferences', 'align') == 'right'
|
||||
|
||||
@@ -440,6 +442,8 @@ module Submissions
|
||||
|
||||
value = TextUtils.maybe_rtl_reverse(Array.wrap(value).join(', '))
|
||||
|
||||
value = TextUtils.mask_value(value) if field.dig('preferences', 'mask').present?
|
||||
|
||||
text_params = { font:, fill_color:, font_size: }
|
||||
text_params[:line_height] = text_params[:font_size] * 1.6 if font_name == COURIER_FONT
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module TextUtils
|
||||
RTL_REGEXP = /[\p{Hebrew}\p{Arabic}]/
|
||||
MASK_REGEXP = /[^\s\-_\[\]\(\)\+\?\.\,]/
|
||||
MASK_SYMBOL = 'X'
|
||||
|
||||
module_function
|
||||
|
||||
@@ -13,6 +15,10 @@ module TextUtils
|
||||
false
|
||||
end
|
||||
|
||||
def mask_value(text)
|
||||
text.to_s.gsub(MASK_REGEXP, MASK_SYMBOL)
|
||||
end
|
||||
|
||||
def maybe_rtl_reverse(text)
|
||||
if text.match?(RTL_REGEXP)
|
||||
TwitterCldr::Shared::Bidi
|
||||
|
||||
Reference in New Issue
Block a user