0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-25 07:58:49 -05:00

Minor change on translation approach on form errors.

This commit is contained in:
Andrey Antukh 2016-04-12 22:57:00 +03:00
parent 63e5e68fc6
commit c314a4cde9
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
5 changed files with 13 additions and 7 deletions

View file

@ -76,9 +76,13 @@
(defrecord UpdatePassword [data] (defrecord UpdatePassword [data]
rs/WatchEvent rs/WatchEvent
(-apply-watch [_ state s] (-apply-watch [_ state s]
(letfn [(on-error [err] (letfn [(on-error [{payload :payload :as data}]
(uum/error (tr "errors.profile.update-password") {:timeout 3000}) (if (= (:type payload) :form/validation)
(rx/empty))] (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) (let [params {:old-password (:old-password data)
:password (:password-1 data)}] :password (:password-1 data)}]
(->> (rp/req :update/password params) (->> (rp/req :update/password params)

View file

@ -40,6 +40,9 @@
"profile.password-saved" "Password saved successfully!" "profile.password-saved" "Password saved successfully!"
"history.alert-message" "You are seeng version %s" "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.required" "This field is mandatory"
"errors.form.string" "Should be string" "errors.form.string" "Should be string"
"errors.form.number" "Invalid number" "errors.form.number" "Invalid number"

View file

@ -73,8 +73,7 @@
([data schema] ([data schema]
(validate data schema nil)) (validate data schema nil))
([data schema opts] ([data schema opts]
(let [opts (merge {:strip true (let [opts (merge {:strip true}
:translate tr}
opts)] opts)]
(st/validate data schema opts)))) (st/validate data schema opts))))

View file

@ -1,5 +1,6 @@
(ns uxbox.ui.forms (ns uxbox.ui.forms
(:require [sablono.core :refer-macros [html]] (:require [sablono.core :refer-macros [html]]
[uxbox.locales :refer (tr)]
[uxbox.schema :as sc])) [uxbox.schema :as sc]))
(defn input-error (defn input-error
@ -8,7 +9,7 @@
(html (html
[:ul.form-errors [:ul.form-errors
(for [error errors] (for [error errors]
[:li {:key error} error])]))) [:li {:key error} (tr error)])])))
(defn error-class (defn error-class
[errors field] [errors field]

View file

@ -42,7 +42,6 @@
(let [form (rum/react formdata) (let [form (rum/react formdata)
errors (rum/react formerrors) errors (rum/react formerrors)
valid? (sc/valid? form udu/update-password-schema)] valid? (sc/valid? form udu/update-password-schema)]
(println valid?)
(letfn [(on-field-change [field event] (letfn [(on-field-change [field event]
(let [value (dom/event->value event)] (let [value (dom/event->value event)]
(rs/emit! (assign-field-value field value)))) (rs/emit! (assign-field-value field value))))