adding error for a field defined with range that is out of range on extensions

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Alexandre Magno 2019-05-17 22:28:31 +02:00 committed by Andrey Shovkoplyas
parent f3aa376d16
commit 287e097471
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
2 changed files with 48 additions and 32 deletions

View File

@ -1,8 +1,12 @@
(ns status-im.extensions.capacities.components
(:require [status-im.ui.components.react :as react]
(:require
[clojure.string :as string]
[reagent.core :as reagent]
[status-im.ui.components.react :as react]
[status-im.chat.commands.impl.transactions :as transactions]
[status-im.ui.components.button.view :as button]
[re-frame.core :as re-frame]
[status-im.i18n :as i18n]
[status-im.utils.platform :as platform]
[status-im.ui.components.list.views :as list]
[status-im.ui.components.checkbox.view :as checkbox]
@ -25,10 +29,17 @@
(js/clearTimeout id))
(reset! current (js/setTimeout #(on-input-change-text on-change value) delay)))
(defn input [{:keys [keyboard-type style error on-change change-delay placeholder placeholder-text-color selection-color
(defn- in-range [n start end]
(or (string/blank? n) (and (nil? start) (nil? end)) (and (< n end) (> n start))))
(defn input [{:keys [keyboard-type style error min max on-change change-delay placeholder placeholder-text-color selection-color
auto-focus on-submit default-value]}]
(let [input-range (reagent/atom nil)]
(fn []
[react/view
[react/text-input (merge {:placeholder placeholder}
{:on-change-text #(reset! input-range %)}
(when placeholder-text-color {:placeholder-text-color placeholder-text-color})
(when selection-color {:selection-color selection-color})
(when style {:style style})
@ -43,8 +54,12 @@
(let [current (atom nil)]
#(on-input-change-text-delay current on-change % change-delay))
#(on-input-change-text on-change %))}))]
(when-not (in-range @input-range, min, max)
[tooltip/tooltip (i18n/label :t/invalid-range {:min min :max max}) styles/error])
(when error
[tooltip/tooltip error (styles/error error)])])
[tooltip/tooltip error (styles/error error)])])))
(defn touchable-opacity [{:keys [style on-press]} & children]
(into [react/touchable-opacity (merge (when on-press {:on-press #(on-press {})})
@ -139,7 +154,7 @@
'image {:data image :properties {:uri :string :source :string}}
'input {:data input :properties {:on-change :event :error :string :placeholder :string :keyboard-type :keyword
:change-delay? :number :placeholder-text-color :any :selection-color :any
:auto-focus? :boolean :on-submit :event :default-value :any}}
:auto-focus? :boolean :min :number :max :number :on-submit :event :default-value :any}}
'button {:data button :properties {:enabled :boolean :disabled :boolean :on-click :event}}
'link {:data link :properties {:uri :string :text? :string :open-in? {:one-of #{:device :status}}}}
'list {:data flat-list :properties {:data :vector :item-view :view :key? :keyword}}

View File

@ -1023,6 +1023,7 @@
"chaos-unicorn-day": "Chaos Unicorn Day",
"chaos-unicorn-day-details": "\uD83E\uDD84\uD83E\uDD84\uD83E\uDD84\uD83E\uDD84\uD83E\uDD84\uD83E\uDD84\uD83E\uDD84\uD83D\uDE80!",
"invalid-format": "Invalid format\nMust be {{format}}",
"invalid-range": "Invalid format, must be between {{min}} and {{max}}",
"mailserver-format": "enode://{enode-id}:{password}@{ip-address}:{port}",
"bootnode-format": "enode://{enode-id}@{ip-address}:{port}",
"fetch-messages": "↓ Fetch messages",