feat: Add regex validation on form message inputs (#2317)

Co-authored-by: Nithin David Thomas <webofnithin@gmail.com>
Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
Sivin Varghese
2021-06-08 16:32:01 +05:30
committed by GitHub
parent 0a087c95fd
commit 67ce6f5704
5 changed files with 84 additions and 14 deletions

View File

@@ -74,18 +74,25 @@ module WootMessageSeeder
message_type: :template,
content_type: 'form',
content: 'form',
content_attributes: {
items: [
{ name: 'email', placeholder: 'Please enter your email', type: 'email', label: 'Email' },
{ name: 'text_area', placeholder: 'Please enter text', type: 'text_area', label: 'Large Text' },
{ name: 'text', placeholder: 'Please enter text', type: 'text', label: 'text', default: 'defaut value' },
{ name: 'select', label: 'Select Option', type: 'select', options: [{ label: '🌯 Burito', value: 'Burito' },
{ label: '🍝 Pasta', value: 'Pasta' }] }
]
}
content_attributes: sample_form
)
end
def self.sample_form
{
"items": [
{ "name": 'email', "placeholder": 'Please enter your email', "type": 'email', "label": 'Email', "required": 'required',
"pattern_error": 'Please fill this field', "pattern": '^[^\s@]+@[^\s@]+\.[^\s@]+$' },
{ "name": 'text_area', "placeholder": 'Please enter text', "type": 'text_area', "label": 'Large Text', "required": 'required',
"pattern_error": 'Please fill this field' },
{ "name": 'text', "placeholder": 'Please enter text', "type": 'text', "label": 'text', "default": 'defaut value', "required": 'required',
"pattern": '^[a-zA-Z ]*$', "pattern_error": 'Only alphabets are allowed' },
{ "name": 'select', "label": 'Select Option', "type": 'select', "options": [{ "label": '🌯 Burito', "value": 'Burito' },
{ "label": '🍝 Pasta', "value": 'Pasta' }] }
]
}
end
def self.create_sample_articles_message(conversation)
Message.create!(
account: conversation.account,