Stimulus JS & HTML attributes | Avo docs
# avo-2
n
Question about toggling hidden fields: https://docs.avohq.io/2.0/stimulus-integration.html#pre-made-stimulus-methods It is showing the toggle working when
has_country
is false (like a new record) It seems like this pre-made toggle method would not work & do the opposite of the intended effect for an existing record where
has_country
is already true? Since there is no conditional initial hidden value on
country
? I can't figure out how to conditionally apply the
hidden
css based on the
has_country
value on rendering the form
l
yes. it depends of you definition of hidden
it you want it not rendered -> use
visible
if you just want to have a value passed on form submission -> you can use the
hidden
field if you just want it to be in the dom but invisible -> use your approach with adding a
hidden
class
n
Thanks for that. Just some feedback, I think the docs example I linked to should include the block form & conditional check. Also, I feel that these declarations are a bit verbose with the block form, and slightly less verbose with the hash form, but I think having both forms as valid is probably more confusing than it's worth. Is there a performance difference? Maybe this can all be defined with a single block instead of nested?
l
there is a small performance hit just in the block vs object notation. just because we're running a block instead of evaluating a hash
there might be some value in redesigning that api to return a single hash, but that's going to be a bit awkward any way of you do it. there are three levels on which that is applied
view layer: index, edit, show element layer: wrapper, input attribute layer: class, data, style
so any way you do it it's not going to be perfect
but we're open to improvements 💪
and thanks for the feedback