From 6904c89668ed28e572e4b56a4300f46b03cee49b Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 28 Aug 2015 10:46:09 +0200 Subject: [PATCH] Added model email validation. --- .../javascripts/app/models/_application_model.js.coffee | 7 +++++++ app/assets/javascripts/app/models/email_address.js.coffee | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/models/_application_model.js.coffee b/app/assets/javascripts/app/models/_application_model.js.coffee index 01af418c8..a67dd87f4 100644 --- a/app/assets/javascripts/app/models/_application_model.js.coffee +++ b/app/assets/javascripts/app/models/_application_model.js.coffee @@ -138,6 +138,13 @@ class App.Model extends Spine.Model errors[attributeName] = 'didn\'t match' errors["#{attributeName}_confirm"] = '' + # check email + if attribute.type is 'email' && data['params'][attributeName] + if !data['params'][attributeName].match(/\S+@\S+\.\S+/) + errors[attributeName] = 'invalid' + if data['params'][attributeName].match(/ /) + errors[attributeName] = 'invalid' + # check datetime if attribute.tag is 'datetime' if data['params'][attributeName] is 'invalid' diff --git a/app/assets/javascripts/app/models/email_address.js.coffee b/app/assets/javascripts/app/models/email_address.js.coffee index 33691fc13..a44f2b627 100644 --- a/app/assets/javascripts/app/models/email_address.js.coffee +++ b/app/assets/javascripts/app/models/email_address.js.coffee @@ -14,7 +14,7 @@ class App.EmailAddress extends App.Model @configure_attributes = [ { name: 'realname', display: 'Realname', tag: 'input', type: 'text', limit: 250, null: false }, { name: 'email', display: 'Email', tag: 'input', type: 'email', limit: 250, null: false }, - { name: 'channel_id', display: 'Channel', tag: 'select', multiple: false, null: false, relation: 'Channel', nulloption: true, filter: @filterChannel }, + { name: 'channel_id', display: 'Channel', tag: 'select', multiple: false, null: true, relation: 'Channel', nulloption: true, filter: @filterChannel }, { name: 'note', display: 'Note', tag: 'textarea', note: 'Notes are visible to agents only, never to customers.', limit: 250, null: true }, { name: 'updated_at', display: 'Updated', tag: 'datetime', readonly: 1 }, { name: 'active', display: 'Active', tag: 'active', default: true },