Fork me on GitHub
#vrac
<
2020-08-31
>
Vincent Cantin23:08:35

@yogthos I am not sure if you mean the vrac components or the html nodes in the form. For the components, they are not themself visible or disabled. The only choice for them is to be included or not being included in the view at any time. For the html nodes, visible and disabled would be attributes to set in the same way of the value attribute on the input html node.

yogthos23:08:23

ah ok yeah I was referring to html nodes, and doing it the same way as value makes sense

yogthos23:08:56

you would need to differentiate between static and dynamic nodes somehow potentially

yogthos23:08:25

cause some parts of the template can be rendered once if they have no behaviors, but others will need to observe the state and repaint if the state changes

Vincent Cantin23:08:27

(defc numeric [title data]
  (let [form-id (gen-id "form-")] ;; non-reactive binding to a generated unique string
    [:div
     [:label {:for form-id} title]
     [:input {:type :number
              :id form-id
              :value (:value data)
              :disabled (:disabled? data)
              :style {:visibility (if (:visible? data) "visible" "hidden")}
              :on-change (dispatch [:input-change data])}]]))

yogthos23:08:47

ok yeah that's exactly what I was thinking

👍 3
Vincent Cantin23:08:45

(if (:visible? data) "visible" "hidden") is a little special, it’s not the same if than the one that returns html nodes. It’s a if which returns values, as if it was wrapped into a (val ...) block.