From c314a4cde9f83fcdf2b8c4eeed119c313bbaf1cd Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 12 Apr 2016 22:57:00 +0300 Subject: [PATCH] Minor change on translation approach on form errors. --- src/uxbox/data/users.cljs | 10 +++++++--- src/uxbox/locales/en.cljs | 3 +++ src/uxbox/schema.cljs | 3 +-- src/uxbox/ui/forms.cljs | 3 ++- src/uxbox/ui/settings/password.cljs | 1 - 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/uxbox/data/users.cljs b/src/uxbox/data/users.cljs index 5c0f63c56..67f2a9436 100644 --- a/src/uxbox/data/users.cljs +++ b/src/uxbox/data/users.cljs @@ -76,9 +76,13 @@ (defrecord UpdatePassword [data] rs/WatchEvent (-apply-watch [_ state s] - (letfn [(on-error [err] - (uum/error (tr "errors.profile.update-password") {:timeout 3000}) - (rx/empty))] + (letfn [(on-error [{payload :payload :as data}] + (if (= (:type payload) :form/validation) + (rx/of + (forms/assign-errors :profile/password (:payload payload))) + (do + (uum/error (tr "errors.profile.update-password") {:timeout 3000}) + (rx/empty))))] (let [params {:old-password (:old-password data) :password (:password-1 data)}] (->> (rp/req :update/password params) diff --git a/src/uxbox/locales/en.cljs b/src/uxbox/locales/en.cljs index 5363f5924..7f4bf4d94 100644 --- a/src/uxbox/locales/en.cljs +++ b/src/uxbox/locales/en.cljs @@ -40,6 +40,9 @@ "profile.password-saved" "Password saved successfully!" "history.alert-message" "You are seeng version %s" + + "errors.api.form.old-password-not-match" "Incorrect old password" + "errors.form.required" "This field is mandatory" "errors.form.string" "Should be string" "errors.form.number" "Invalid number" diff --git a/src/uxbox/schema.cljs b/src/uxbox/schema.cljs index c2674f383..1aba210cf 100644 --- a/src/uxbox/schema.cljs +++ b/src/uxbox/schema.cljs @@ -73,8 +73,7 @@ ([data schema] (validate data schema nil)) ([data schema opts] - (let [opts (merge {:strip true - :translate tr} + (let [opts (merge {:strip true} opts)] (st/validate data schema opts)))) diff --git a/src/uxbox/ui/forms.cljs b/src/uxbox/ui/forms.cljs index 78ec63fc8..a6ec2cffd 100644 --- a/src/uxbox/ui/forms.cljs +++ b/src/uxbox/ui/forms.cljs @@ -1,5 +1,6 @@ (ns uxbox.ui.forms (:require [sablono.core :refer-macros [html]] + [uxbox.locales :refer (tr)] [uxbox.schema :as sc])) (defn input-error @@ -8,7 +9,7 @@ (html [:ul.form-errors (for [error errors] - [:li {:key error} error])]))) + [:li {:key error} (tr error)])]))) (defn error-class [errors field] diff --git a/src/uxbox/ui/settings/password.cljs b/src/uxbox/ui/settings/password.cljs index 57b786eac..8fb06436c 100644 --- a/src/uxbox/ui/settings/password.cljs +++ b/src/uxbox/ui/settings/password.cljs @@ -42,7 +42,6 @@ (let [form (rum/react formdata) errors (rum/react formerrors) valid? (sc/valid? form udu/update-password-schema)] - (println valid?) (letfn [(on-field-change [field event] (let [value (dom/event->value event)] (rs/emit! (assign-field-value field value))))