[Git][noosfero/noosfero][master] 2 commits: Validates phone numbers

Rodrigo Souto gitlab at mg.gitlab.com
Tue Apr 3 10:45:25 BRT 2018


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
e0b496a6 by Gabriel Silva at 2018-03-27T19:43:35Z
Validates phone numbers

Signed-off-by: Gabriel Silva <gabriel93.silva at gmail.com>

- - - - -
a7c9e350 by Rodrigo Souto at 2018-04-03T13:45:06Z
Merge branch 'phone-validation' into 'master'

Adds validation to phone fields

See merge request noosfero/noosfero!1423
- - - - -


4 changed files:

- app/views/profile_editor/_person_form.html.erb
- + public/javascripts/fields_validators.js
- public/stylesheets/profile-editor.scss
- public/stylesheets/signup.scss


Changes:

=====================================
app/views/profile_editor/_person_form.html.erb
=====================================
--- a/app/views/profile_editor/_person_form.html.erb
+++ b/app/views/profile_editor/_person_form.html.erb
@@ -1,3 +1,5 @@
+<%= javascript_include_tag 'fields_validators' %>
+
 <% @person ||= @profile %>
 <% editing_profile ||= false %>
 
@@ -11,9 +13,10 @@
 <%= optional_field(@person, 'description', f.text_area(:description, :rows => 5, :rel => _('Description'))) %>
 <%= optional_field(@person, 'preferred_domain', select_preferred_domain(:profile_data)) %>
 <%= optional_field(@person, 'contact_information', f.text_field(:contact_information, :rel => _('Contact information'))) %>
-<%= optional_field(@person, 'contact_phone', labelled_form_field(_('Home phone'), text_field(:profile_data, :contact_phone, :rel => _('Contact phone')))) %>
-<%= optional_field(@person, 'cell_phone', f.text_field(:cell_phone, :rel => _('Cell phone'))) %>
-<%= optional_field(@person, 'comercial_phone', f.text_field(:comercial_phone, :rel => _('Comercial phone'))) %>
+<%= optional_field(@person, 'contact_phone', labelled_form_field(_('Home phone'), text_field(:profile_data, :contact_phone, :rel => _('Contact phone'),
+                                                                                                                            :placeholder => _('With area code, only numbers')))) %>
+<%= optional_field(@person, 'cell_phone', f.text_field(:cell_phone, :rel => _('Cell phone'), :placeholder => _('With area code, only numbers'))) %>
+<%= optional_field(@person, 'comercial_phone', f.text_field(:comercial_phone, :rel => _('Comercial phone'), :placeholder => _('With area code, only numbers'))) %>
 <%= optional_field(@person, 'jabber_id', f.text_field(:jabber_id, :rel => _('Jabber'))) %>
 <%= optional_field(@person, 'personal_website', f.text_field(:personal_website, :rel => _('Personal website'))) %>
 <%= optional_field(@person, 'sex', f.radio_group(:profile_data, :sex, [ ['male',_('Male')], ['female',_('Female')] ])) %>


=====================================
public/javascripts/fields_validators.js
=====================================
--- /dev/null
+++ b/public/javascripts/fields_validators.js
@@ -0,0 +1,19 @@
+(function() {
+
+$(document).ready(function() {
+  $('form').on('keyup', '#profile_data_contact_phone, ' +
+                        '#profile_data_cell_phone, ' +
+                        '#profile_data_comercial_phone', function() {
+    var regex = /^\d{5,15}$/
+    var submitButton = $(this).closest('form').find('input[type=submit]')
+    if (!regex.test($(this).val())) {
+      $(this).addClass('invalid')
+      submitButton.prop('disabled', true)
+    } else {
+      $(this).removeClass('invalid')
+      submitButton.prop('disabled', false)
+    }
+  })
+})
+
+})()


=====================================
public/stylesheets/profile-editor.scss
=====================================
--- a/public/stylesheets/profile-editor.scss
+++ b/public/stylesheets/profile-editor.scss
@@ -1,3 +1,13 @@
+.controller-profile_editor form {
+  input[type=submit]:disabled {
+    opacity: 0.5;
+    pointer-events: none;
+  }
+
+  input[type=text].invalid {
+    box-shadow: 0px 0px 3px red;
+  }
+}
 
 .controller-profile_editor .categorie_box .button {
   float: left;


=====================================
public/stylesheets/signup.scss
=====================================
--- a/public/stylesheets/signup.scss
+++ b/public/stylesheets/signup.scss
@@ -105,6 +105,11 @@
   -webkit-border-radius: 7px;
   max-height: none;
   height: 39px;
+
+  &:disabled {
+    opacity: 0.5;
+    pointer-events: none;
+  }
 }
 
 .action-account-signup .no-boxes {



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/7cd9332e8ea74589c5ac8d463a26b1d9777c881f...a7c9e350b675e60eaeed3b7eda1a2b91a9ca5fa3

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/7cd9332e8ea74589c5ac8d463a26b1d9777c881f...a7c9e350b675e60eaeed3b7eda1a2b91a9ca5fa3
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180403/d657aa75/attachment-0001.html>


More information about the Noosfero-dev mailing list