From 900a98b4bb05ef00eaed776f84e3a8ad63b4553a Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 6 Nov 2014 14:33:35 +1100 Subject: [PATCH] Display errors on checkout State field --- app/helpers/checkout_helper.rb | 13 ++++++++++++- app/views/checkout/_billing.html.haml | 3 +-- app/views/shared/_validated_select.html.haml | 6 ++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 app/views/shared/_validated_select.html.haml diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index 6441cd619e..f5c10c3649 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -36,7 +36,18 @@ module CheckoutHelper "ng-class" => "{error: !fieldValid('#{path}')}" }.merge args - render partial: "shared/validated_input", locals: {name: name, path: path, attributes: attributes} + render "shared/validated_input", name: name, path: path, attributes: attributes + end + + def validated_select(name, path, options, args = {}) + attributes = { + required: true, + id: path, + "ng-model" => path, + "ng-class" => "{error: !fieldValid('#{path}')}" + }.merge args + + render "shared/validated_select", name: name, path: path, options: options, attributes: attributes end def reset_order diff --git a/app/views/checkout/_billing.html.haml b/app/views/checkout/_billing.html.haml index f9b42827db..c1cafa6161 100644 --- a/app/views/checkout/_billing.html.haml +++ b/app/views/checkout/_billing.html.haml @@ -39,8 +39,7 @@ = validated_input "City", "order.bill_address.city" .small-6.columns - = ba.select :state_id, @order.billing_address.country.states.map{|c|[c.name, c.id]}, {include_blank: false}, - "ng-model" => "order.bill_address.state_id", required: true + = validated_select "State", "order.bill_address.state_id", [[]]+@order.billing_address.country.states.map{|c|[c.name, c.id]} .row .small-6.columns = validated_input "Postcode", "order.bill_address.zipcode" diff --git a/app/views/shared/_validated_select.html.haml b/app/views/shared/_validated_select.html.haml new file mode 100644 index 0000000000..35bdd971b3 --- /dev/null +++ b/app/views/shared/_validated_select.html.haml @@ -0,0 +1,6 @@ +%label{for: path}= name + += select_tag path, options_for_select(options), attributes + +%small.error.medium.input-text{"ng-show" => "!fieldValid('#{path}')"} + = "{{ fieldErrors('#{path}') }}"