# PlutoUI Buttons to push user input to a list

**URL:** https://discourse.julialang.org/t/plutoui-buttons-to-push-user-input-to-a-list/69369
**Category:** Pluto
**Tags:** interactivity
**Created:** [October 7, 2021, 1:10pm UTC](https://discourse.julialang.org/t/plutoui-buttons-to-push-user-input-to-a-list/69369 "2021-10-07T13:10:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dmoored4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmoored4/32/18311_2.png) [@dmoored4](https://discourse.julialang.org/u/dmoored4)
#### Post date: [October 7, 2021, 1:10pm UTC](https://discourse.julialang.org/t/plutoui-buttons-to-push-user-input-to-a-list/69369/1 "2021-10-07T13:10:29Z")

</div>

I would like to append some user input to a list by using a `Button` to submit it. The problem is that every change in the user input results in a new submission, regardless of whether the submit button has been clicked.

I think the general scheme would be something like this:

```julia
my_list = []

@bind some_input TextField()

@bind submit_button Button()

let submit_button 
    push!(my_list, some_input)
end

```

I’ve also tried to use a function like this but it did not solve the problem either:

```julia
function submit_function(b, input)
    push!(my_list, input)
end

submit_function(submit_button , some_input)

```

In both cases, if the first input to be added is “here’s stuff”, the result in `my_list` is:

```julia
["h", "he", "her", "here", "here's", "here's ", "here's s", ... , "here's stuff"]

```

…and so on. I also briefly explored using other html user interface tools but that appeared to have the same behavior.

For other cases I’ve done a workaround using a `CheckBox` and executing based on whether checked or not, but this will become impractical for the current problem. Am I using `Button`s incorrectly or is this an inherent limitation? Are there any alternatives to interactively adding user input to a list?

If it makes any difference, what I ultimately want to do is have the ability for a user to input multiple values using a mix of `Select`, `NumberField`, `Slider`, `TextField` which are all contained in a `Type`. Then once all fields are complete, the user can submit, that type will be instantiated and pushed to the list, and the fields will return to default values.

Thanks in advance for advice!

---

<div class="post-metadata">

### Author: ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)
#### Post date: [October 7, 2021, 1:31pm UTC](https://discourse.julialang.org/t/plutoui-buttons-to-push-user-input-to-a-list/69369/2 "2021-10-07T13:31:04Z")

</div>

The issue is that the let-cell is executed also for any change of `some_input`, which is not what you want here. The solution is to wrap it into a ref:

```julia
# ╔═╡ 248637d9-fbb1-4b9b-9ba1-23539206b3d0
using PlutoUI

# ╔═╡ c2fc96ab-6b86-4cf5-8d34-47443e3c206a
my_list = String[]

# ╔═╡ a7b70b21-ff49-4521-ba97-d5b67dbf1e26
@bind some_input TextField()

# ╔═╡ 6104110e-4b5a-49c9-a4d9-2f9653de01f5
typeof(some_input)

# ╔═╡ c475d4ba-f832-4f97-b116-f8d95cbed4c9
some_input_ref = Ref{String}()

# ╔═╡ 6dc037ab-90f8-4579-bc94-93f3ffb88f5f
some_input_ref[] = some_input

# ╔═╡ 89549754-af0d-4d33-82db-257d815dd006
@bind submit_button Button()

# ╔═╡ 43d1b02f-36dd-4ad8-9fa1-1356ca6edbc0
let submit_button 
	length(some_input_ref[]) > 0 && push!(my_list, some_input_ref[])
end

# ╔═╡ 529211bb-eceb-41f3-abe6-d6f7fe31cca0
my_list

```

---

<div class="post-metadata">

### Author: ![dmoored4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmoored4/32/18311_2.png) [@dmoored4](https://discourse.julialang.org/u/dmoored4)
#### Post date: [October 7, 2021, 3:02pm UTC](https://discourse.julialang.org/t/plutoui-buttons-to-push-user-input-to-a-list/69369/3 "2021-10-07T15:02:09Z")

</div>

worked perfectly! I’ll have to read the documentation for Ref so I can understand it a little better. Thank you!
