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:
parent
f3aa376d16
commit
287e097471
|
@ -1,16 +1,20 @@
|
||||||
(ns status-im.extensions.capacities.components
|
(ns status-im.extensions.capacities.components
|
||||||
(:require [status-im.ui.components.react :as react]
|
(:require
|
||||||
[status-im.chat.commands.impl.transactions :as transactions]
|
[clojure.string :as string]
|
||||||
[status-im.ui.components.button.view :as button]
|
[reagent.core :as reagent]
|
||||||
[re-frame.core :as re-frame]
|
[status-im.ui.components.react :as react]
|
||||||
[status-im.utils.platform :as platform]
|
[status-im.chat.commands.impl.transactions :as transactions]
|
||||||
[status-im.ui.components.list.views :as list]
|
[status-im.ui.components.button.view :as button]
|
||||||
[status-im.ui.components.checkbox.view :as checkbox]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.ui.components.colors :as colors]
|
[status-im.i18n :as i18n]
|
||||||
[status-im.ui.components.icons.vector-icons :as icons]
|
[status-im.utils.platform :as platform]
|
||||||
[status-im.ui.components.tooltip.views :as tooltip]
|
[status-im.ui.components.list.views :as list]
|
||||||
[status-im.ui.components.text-input.styles :as styles]
|
[status-im.ui.components.checkbox.view :as checkbox]
|
||||||
[status-im.extensions.capacities.map :as map-component]))
|
[status-im.ui.components.colors :as colors]
|
||||||
|
[status-im.ui.components.icons.vector-icons :as icons]
|
||||||
|
[status-im.ui.components.tooltip.views :as tooltip]
|
||||||
|
[status-im.ui.components.text-input.styles :as styles]
|
||||||
|
[status-im.extensions.capacities.map :as map-component]))
|
||||||
|
|
||||||
(defn button [{:keys [on-click enabled disabled] :as m} label]
|
(defn button [{:keys [on-click enabled disabled] :as m} label]
|
||||||
[button/secondary-button (merge {:disabled? (or (when (contains? m :enabled) (or (nil? enabled) (false? enabled))) disabled)}
|
[button/secondary-button (merge {:disabled? (or (when (contains? m :enabled) (or (nil? enabled) (false? enabled))) disabled)}
|
||||||
|
@ -25,26 +29,37 @@
|
||||||
(js/clearTimeout id))
|
(js/clearTimeout id))
|
||||||
(reset! current (js/setTimeout #(on-input-change-text on-change value) delay)))
|
(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]}]
|
auto-focus on-submit default-value]}]
|
||||||
[react/view
|
|
||||||
[react/text-input (merge {:placeholder placeholder}
|
(let [input-range (reagent/atom nil)]
|
||||||
(when placeholder-text-color {:placeholder-text-color placeholder-text-color})
|
(fn []
|
||||||
(when selection-color {:selection-color selection-color})
|
[react/view
|
||||||
(when style {:style style})
|
[react/text-input (merge {:placeholder placeholder}
|
||||||
(when keyboard-type {:keyboard-type keyboard-type})
|
{:on-change-text #(reset! input-range %)}
|
||||||
(when auto-focus {:auto-focus auto-focus})
|
(when placeholder-text-color {:placeholder-text-color placeholder-text-color})
|
||||||
(when default-value {:default-value default-value})
|
(when selection-color {:selection-color selection-color})
|
||||||
(when on-submit
|
(when style {:style style})
|
||||||
{:on-submit-editing #(on-submit {})})
|
(when keyboard-type {:keyboard-type keyboard-type})
|
||||||
(when on-change
|
(when auto-focus {:auto-focus auto-focus})
|
||||||
{:on-change-text
|
(when default-value {:default-value default-value})
|
||||||
(if change-delay
|
(when on-submit
|
||||||
(let [current (atom nil)]
|
{:on-submit-editing #(on-submit {})})
|
||||||
#(on-input-change-text-delay current on-change % change-delay))
|
(when on-change
|
||||||
#(on-input-change-text on-change %))}))]
|
{:on-change-text
|
||||||
(when error
|
(if change-delay
|
||||||
[tooltip/tooltip error (styles/error error)])])
|
(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)])])))
|
||||||
|
|
||||||
(defn touchable-opacity [{:keys [style on-press]} & children]
|
(defn touchable-opacity [{:keys [style on-press]} & children]
|
||||||
(into [react/touchable-opacity (merge (when on-press {:on-press #(on-press {})})
|
(into [react/touchable-opacity (merge (when on-press {:on-press #(on-press {})})
|
||||||
|
@ -139,7 +154,7 @@
|
||||||
'image {:data image :properties {:uri :string :source :string}}
|
'image {:data image :properties {:uri :string :source :string}}
|
||||||
'input {:data input :properties {:on-change :event :error :string :placeholder :string :keyboard-type :keyword
|
'input {:data input :properties {:on-change :event :error :string :placeholder :string :keyboard-type :keyword
|
||||||
:change-delay? :number :placeholder-text-color :any :selection-color :any
|
: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}}
|
'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}}}}
|
'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}}
|
'list {:data flat-list :properties {:data :vector :item-view :view :key? :keyword}}
|
||||||
|
|
|
@ -1023,6 +1023,7 @@
|
||||||
"chaos-unicorn-day": "Chaos Unicorn Day",
|
"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!",
|
"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-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}",
|
"mailserver-format": "enode://{enode-id}:{password}@{ip-address}:{port}",
|
||||||
"bootnode-format": "enode://{enode-id}@{ip-address}:{port}",
|
"bootnode-format": "enode://{enode-id}@{ip-address}:{port}",
|
||||||
"fetch-messages": "↓ Fetch messages",
|
"fetch-messages": "↓ Fetch messages",
|
||||||
|
|
Loading…
Reference in New Issue