Copying from an input field to another, with a button

5 views
Skip to first unread message

Dan Campbell

unread,
Sep 2, 2015, 11:37:41 AM9/2/15
to Enfocus

Hi,

I can't seem to get a value copied from one field, to another, triggered by a button click.  The code below copies the contents of <name> to <othername> during load, as its instructed.  But if I input a value into <name>, and then click the <btn_copynametoothername> button, nothing happens.

(The different button names don't really mean anything.  I'm just randomly trying different things, at this point).


defn ^:export init []
  ( js/alert "Testing init" )
  ( go ( let [ response ( <! (http/get "/websample" ))
              body ( :body response )
              s_name-value ( ef/from "#name" ( ef/read-form-input ))]

         ; leave this for testing later
         ; ( js/alert s_name-value )

         ( ef/at "#name" ( ef/content ( :name body )))
         
         ; copy content of name to othername 
         ; This works, as it should.
         ( ef/at "#othername" ( ef/set-prop :value s_name-value ))

         ( ef/at "#button1" ( ev/listen :click ( say-goodbye )))


         ; Execute say-whatthe, when buttonsubmit is clicked.
         ( ef/at [ :#buttonsubmit ] ( ev/listen :click ( say-whatthe )))


         ; Copy contents of name to othername
         ; Doesn't work yet 09/01/2015
         ( ef/at [ :#btn_copynametoothername ] ( ev/listen :click  
                           ( ef/at "#name" ( ef/set-prop :value ( ef/from "#othername" ( ef/read-form-input ))))))





xavi

unread,
Sep 3, 2015, 3:38:04 AM9/3/15
to Enfocus
I think the code in the last line is copying the value from #othername to #name, not the other way around as you say.

Dan Campbell

unread,
Sep 3, 2015, 8:12:41 AM9/3/15
to enf...@googlegroups.com
         
You're right xavi, thanks.  Unfortunately, even after reversing the function calls, it still has no effect.


         ( ef/at [ :#btn_copynametoothername ] ( ev/listen :click  
                    ( ef/at "#othername" ( ef/set-prop :value ( ef/from "#name" ( ef/read-form-input )))))) 


On Thu, Sep 3, 2015 at 3:38 AM, xavi <xavi.c...@gmail.com> wrote:
I think the code in the last line is copying the value from #othername to #name, not the other way around as you say.

--

---
You received this message because you are subscribed to a topic in the Google Groups "Enfocus" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/enfocus/2CwiJoV1rHU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to enfocus+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Campbell

unread,
Sep 3, 2015, 8:18:25 AM9/3/15
to enf...@googlegroups.com
You're right xavi, thanks.  Unfortunately, even after reversing the function calls, it still has no effect on the button action.  It gets executed when the page is loaded, but not when the button is clicked.  

So if we throw in an alert call,

         ( ef/at [ :#btn_copynametoothername ] ( ev/listen :click  
                                                           ( do 
                                                             ( js/alert "this part works" )
                    ( ef/at "#othername" ( ef/set-prop ( ef/from "#name" ( ef/read-form-input )))))) 
         )

, the "this part works" shows up when the page is refreshed.  But the button click has no effect.

This something else I'm missing.  Something careless and dumb.

Anyway, thanks for the input, I'll try removing and adding a few things.





On Thu, Sep 3, 2015 at 3:38 AM, xavi <xavi.c...@gmail.com> wrote:
I think the code in the last line is copying the value from #othername to #name, not the other way around as you say.

ckirkendall

unread,
Sep 3, 2015, 8:43:05 AM9/3/15
to Enfocus
Dan,
Listen takes a funciton and you are passing the result of (at...) to it.  You need to pass #(...) or (fn [ev]..).  

Creighton
To unsubscribe from this group and all its topics, send an email to enfocus+unsubscribe@googlegroups.com.

Dan Campbell

unread,
Sep 3, 2015, 9:07:47 AM9/3/15
to enf...@googlegroups.com
You're right xavi, thanks.  Unfortunately, the othername assignment doesn't take place.  There doesn't seem to be any problem retrieving the value of name or othername, but making the assignment in the button has no effect.

So, these two will work as expected,

        ( ef/at [ :#btn_copynametoothername ] ( ev/listen :click ( do
                                                         #( js/alert ( ef/from "#name" ( ef/read-form-input ))))))
        
        ( ef/at [ :#btn_copynametoothername ] ( ev/listen :click ( do
                                                         #( js/alert ( ef/from "#othername" ( ef/read-form-input ))))))

, but this has no effect:

        ( ef/at [ :#btn_copynametoothername ] ( ev/listen :click ( do
                                                         ( ef/at "#othername" ( ef/set-prop ( ef/from "#name" ( ef/read-form-input )))))))


Even if the at/set-prop applies to a simple constant string, it won't execute.  So at/set-prop will execute upon load, in this code, but will not execute in a button event.




On Thu, Sep 3, 2015 at 3:38 AM, xavi <xavi.c...@gmail.com> wrote:
I think the code in the last line is copying the value from #othername to #name, not the other way around as you say.
--

---
You received this message because you are subscribed to a topic in the Google Groups "Enfocus" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/enfocus/2CwiJoV1rHU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to enfocus+u...@googlegroups.com.

Dan Campbell

unread,
Sep 3, 2015, 9:08:52 AM9/3/15
to enf...@googlegroups.com
Ah, ok.  I'll give that a try, thanks Creighton.


To unsubscribe from this group and all its topics, send an email to enfocus+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to a topic in the Google Groups "Enfocus" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/enfocus/2CwiJoV1rHU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to enfocus+u...@googlegroups.com.

Dan Campbell

unread,
Sep 3, 2015, 9:32:20 AM9/3/15
to enf...@googlegroups.com
That's the ticket, thank you sir.
Reply all
Reply to author
Forward
0 new messages