feat: Support Regex validation for custom attributes (#7856)
This allows a user to add/update a custom regex and a cue while defining custom attributes(Only applicable for type- text). While adding/editing custom attributes, the values are validated against the attribute definition regex, and if it is incorrect, a cue message or default error message is shown and restricts invalid values from being saved. Fixes: #6866
This commit is contained in:
@@ -11,7 +11,9 @@ RSpec.describe Inboxes::UpdateWidgetPreChatCustomFieldsJob do
|
||||
pre_chat_message = 'Share your queries here.'
|
||||
custom_attribute = {
|
||||
'attribute_key' => 'developer_id',
|
||||
'attribute_display_name' => 'Developer Number'
|
||||
'attribute_display_name' => 'Developer Number',
|
||||
'regex_pattern' => '^[0-9]*',
|
||||
'regex_cue' => 'It should be only digits'
|
||||
}
|
||||
let!(:account) { create(:account) }
|
||||
let!(:web_widget) do
|
||||
@@ -23,7 +25,8 @@ RSpec.describe Inboxes::UpdateWidgetPreChatCustomFieldsJob do
|
||||
described_class.perform_now(account, custom_attribute)
|
||||
expect(web_widget.reload.pre_chat_form_options['pre_chat_fields']).to eq [
|
||||
{ 'label' => 'Developer Number', 'name' => 'developer_id', 'placeholder' => 'Developer Number',
|
||||
'values' => nil }, { 'label' => 'Full Name', 'name' => 'full_name' }
|
||||
'values' => nil, 'regex_pattern' => '^[0-9]*', 'regex_cue' => 'It should be only digits' },
|
||||
{ 'label' => 'Full Name', 'name' => 'full_name' }
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user