Genie Discord forum

Author AvatarMordegai
8/15/2023, 8:42:26 AM

I'd like to have the user input one or more values, depending on their needs. Is there an example somewhere that adds input fields on the fly? I'm thinking of having a '+' button to add extra fields.

Author AvatarPere
8/15/2023, 8:54:44 AM

check out this example with a button to add new sliders

https://github.com/BuiltWithGenie/NNtraining

Author AvatarPere
8/15/2023, 8:55:55 AM

these are the relevant parts in app.jl

    @onchange add_layer begin
        @show layer_neurons
        push!(layer_neurons,1)
        layer_neurons = copy(layer_neurons)
    end
    @onchange remove_layer begin
        @show layer_neurons
        pop!(layer_neurons)
        layer_neurons = copy(layer_neurons)
    end
Author AvatarPere
8/15/2023, 8:57:40 AM

and app.jl.html

<div v-for="neurons,index in layer_neurons">
    Layer {{index+2}} <q-slider :min="1" v-model="layer_neurons[index]" label="" :max="16" :step="1"></q-slider>
</div>
Author AvatarMordegai
8/15/2023, 5:05:28 PM

I kinda got it working. I see that elements are added to the array but I don't see the components being displayed. Guess I'm overlooking something. The html is:

Author AvatarMordegai
8/15/2023, 5:06:03 PM

@in dem_percentages = 1.0 @in dem_tiers = Currency(25000) @in add_dem_tier = false @in remove_dem_tier = false

@onchange add_dem_tier begin
    @show dem_percentages
    push!(dem_percentages, last(dem_percentages) + 1)
    dem_percentages = copy(dem_percentages)

    # @show dem_tiers
    # push!(dem_tiers, last(dem_tiers) + 1000)
    # dem_tiers = copy(dem_tiers)
end

@onchange remove_dem_tier begin
    @show dem_percentages
    pop!(dem_percentages)
    dem_percentages = copy(dem_percentages)

    # @show dem_tiers
    # pop!(dem_tiers)
    # dem_tiers = copy(dem_tiers)
end
Author AvatarMordegai
8/15/2023, 5:06:36 PM

The code above is wrapped in a @app begin end block.

Author AvatarMordegai
8/15/2023, 5:07:26 PM

Currency is defined as Currency = Fixed(2)

Author AvatarMordegai
8/15/2023, 5:08:03 PM

Fixed is imported from FixedPointDecimals

Author AvatarMordegai
8/15/2023, 5:19:52 PM

I also noticed the interface seems to lag one click behind. The first time I select the 'SuMSy' menu item (for which I want to add the components), it jumps back to the previous selection. The second time I see what I expect to see. The first time I click on any button, nothing happens. The second time, the action from the previous button is executed, From the on, the action of a button is only executed when the next button is clicked. It's weird! Full code is available at https://github.com/HapponomyOrg/HapponomyCockpit.jl/tree/main/app/inequality

Author AvatarPere
8/16/2023, 8:31:10 AM

I believe the issue is that you're using a custom type in the array. The reactive variables tagged with @in or @out are mirrored in the front end as Javascript variables, so they should be of compatible types like Int or String

Author AvatarMordegai
8/17/2023, 1:49:23 PM

Ok, I got it working ... well, sorta. Everything works fine except for one thing. The first time I select SuMSy as the model, the selection jumps back to Standard. After that first glitch everything works just fine. I checked in the updated code if you want to have a look.