From 2a4737147ff2c6bfec2411c1180b89318b51e142 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 16 Jun 2016 16:32:10 +1000 Subject: [PATCH] Tweaking the way new customer form error messages are display for latest version of AngularJS --- .../directives/new_customer_dialog.js.coffee | 11 ++++++----- .../templates/admin/new_customer_dialog.html.haml | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/admin/customers/directives/new_customer_dialog.js.coffee b/app/assets/javascripts/admin/customers/directives/new_customer_dialog.js.coffee index 46292ae85c..f2dae5836b 100644 --- a/app/assets/javascripts/admin/customers/directives/new_customer_dialog.js.coffee +++ b/app/assets/javascripts/admin/customers/directives/new_customer_dialog.js.coffee @@ -3,18 +3,19 @@ angular.module("admin.customers").directive 'newCustomerDialog', ($compile, $inj scope: true link: (scope, element, attr) -> scope.CurrentShop = CurrentShop - scope.submitted = null + scope.submitted = false scope.email = "" scope.errors = [] - scope.addCustomer = (valid) -> - scope.submitted = scope.email + scope.addCustomer = -> + scope.new_customer_form.$setPristine() + scope.submitted = true scope.errors = [] - if valid + if scope.new_customer_form.$valid Customers.add(scope.email).$promise.then (data) -> if data.id scope.email = "" - scope.submitted = null + scope.submitted = false template.dialog('close') , (response) -> if response.data.errors diff --git a/app/assets/javascripts/templates/admin/new_customer_dialog.html.haml b/app/assets/javascripts/templates/admin/new_customer_dialog.html.haml index e30cfcd607..525e777eac 100644 --- a/app/assets/javascripts/templates/admin/new_customer_dialog.html.haml +++ b/app/assets/javascripts/templates/admin/new_customer_dialog.html.haml @@ -2,14 +2,14 @@ .text-normal.margin-bottom-30.text-center = t('admin.customers.index.add_a_new_customer_for', shop_name: "{{ CurrentShop.shop.name }}:") - %form{ name: 'new_customer_form', novalidate: true } + %form{ name: 'new_customer_form', novalidate: true, ng: { submit: "addCustomer()" }} .text-center.margin-bottom-30 %input.fullwidth{ type: 'email', name: 'email', required: true, placeholder: t('admin.customers.index.customer_placeholder'), ng: { model: "email" } } - %div{ ng: { show: "email == submitted" } } + %div{ ng: { show: "submitted && new_customer_form.$pristine" } } .error{ ng: { show: "(new_customer_form.email.$error.email || new_customer_form.email.$error.required)" } } = t('admin.customers.index.valid_email_error') .error{ ng: { repeat: "error in errors", bind: "error" } } .text-center - %input.button.red.icon-plus{ type: 'submit', value: t('admin.customers.index.add_customer'), ng: { click: 'addCustomer(new_customer_form.email.$valid)' } } + %input.button.red.icon-plus{ type: 'submit', value: t('admin.customers.index.add_customer') }