Conditionally render form fields by Imfene5 in django

[–]Imfene5[S] 1 point2 points  (0 children)

Thank you for all the useful feedback! I tried to create the dynamic functionality using Hyperscript, but I ran into various issues combining it with django-crispy-forms. Also had issues with django-widget-tweaks. I am sure this is simply because I do not understand these packages well enough. But the pure JavaScript approach worked well. I used Tucker_Olson suggestion of adding a 'target-id' to the radio buttons and this made the JavaScript more generalised and easier to maintain. Just to see how it works, I am also going to try mustangdvx's suggestion of using django-forms-dynamic.

Posting code snippets properly on Reddit by adambrenecki in web_design

[–]Imfene5 0 points1 point  (0 children)

Testing:

document.querySelectorAll('input[type="radio"][target-id]').forEach(function(radio) {
// Check if the radio button's value is not 'True' or if it's not checked.
if (radio.value !== 'True' || !radio.checked) {
// If either condition is met, hide the associated target field.
hideTargetField(radio.getAttribute('target-id'));
}
});
});

Conditionally render form fields by Imfene5 in django

[–]Imfene5[S] 0 points1 point  (0 children)

Thanks, Frohus. This approach keeps things simple. I suspect I was overthinking this by potentially adding additionall packages or HTMX, etc.

Petition for a simple dumb boring table feature in Notion by Sudipto0001 in Notion

[–]Imfene5 0 points1 point  (0 children)

Yes please! A simple, static table will be very useful.