Fork me on GitHub
#re-frame
<
2016-02-01
>
mbertheau08:02:59

@sooheon: I guess what you could do is in the on-change dispatch to do nothing unless all characters are complete characters. Or alternatively ignore all on-change and use only on-blur.

mbertheau09:02:13

@sooheon: also, please let me know when you find a solution simple_smile

nberger12:02:21

@sooheon are you using :value or :default-value on the input? I guess :value could cause this behavior

mbertheau13:02:49

@nberger: using :default-value how would you reset the input's value from the outside?

nberger14:02:38

@mbertheau I guess you have to rely on something else. But in many cases you don't need to do that. In this particular case, is it needed to be able to reset the value from the outside, after the initial render of the component?

mbertheau15:02:26

@nberger Yes. I guess I could trigger a re-mount with a different key.

nberger15:02:41

Yep, that would be a way

yenda17:02:07

if I change a value like that : (set! (.-value el) var)

yenda17:02:22

is it possible to make it trigger the on-change event on el ?

yenda17:02:21

the purpose of the event is to add the value of a clickable var into the currently focused input

yenda17:02:07

I couldn't come up with a "re-frame way" of doing that

yenda17:02:47

I hoped that the on-change event on the updated input field would trigger when the text changes but it doesn't

yenda17:02:51

I don't like the approach but I'm not sure if there is a way to achieve this with handlers

mbertheau17:02:37

@yenda Is that a paste function?

yenda18:02:21

Yes kinda

yenda18:02:05

It inserts the value you click on in the input field you are typing

yenda18:02:55

But it doesn't trigger the on-change event on this field so it is not handled

yenda18:02:11

Which is my problem

yenda18:02:06

@mbertheau do you know of any example of similar paste function ?

mbertheau18:02:49

@yenda: And you have two problems doing that the re-frame way - finding the right spot in app-db for activeElement and knowing the selection to insert in the right position, correct?

mbertheau18:02:20

@yenda: maybe in the component you could add a callback to the DOM element that dispatches the on-change manually and call that in on-mouse-down.

yenda18:02:19

@mbertheau: yes that is exactly my two problems

yenda18:02:44

which are solved by that function but I find it really ugly

yenda18:02:23

i have not used callbacks yet but I'll give it a try

mbertheau18:02:55

I agree it's ugly

hugobessaa19:02:28

@mbertheau: I'm resetting :default-value using the will-receive-props react element method

hugobessaa19:02:20

(let [state (reagent/atom {:value (or default-value "")})]

     (reagent/create-class
      {:component-will-receive-props
       (fn [_ [_ props]]
         (let [default-value (:default-value props)
               state-value   (:value @state)]
           (when (not= default-value state-value)
             (swap! state assoc :value default-value))))

hugobessaa19:02:13

This changes the value from my component state when the wrapper component changes the default-value it is passing to it

hugobessaa19:02:30

My use case is that I have a generic input with state

hugobessaa19:02:52

And want to control it's value sometimes (e.g. search query string changes)