mojolicious / dom.js

:crystal_ball: A fast and very small HTML/XML DOM parser with CSS selectors
https://www.npmjs.com/package/@mojojs/dom
MIT License
20 stars 3 forks source link

add a way to pre-select checkboxes and radio buttons #10

Closed ralyodio closed 1 year ago

ralyodio commented 1 year ago
    <div class="field">
        <label for="type">Employee Type:</label>
        <ul class="list">
        <% for (let type of types) { %>
            <li>
                <label>
                    %= await ctx.radioButtonTag('type', { value: type.value, checked: gig.type === type.value})
                    <%= type.label %>
                </label>
            </li>
        <% } %>
        </ul>
    </div>

This would be the ideal API imo, where checked attribute would be set if statement is true.

Same goes for checkboxes vs. radio buttons.

ralyodio commented 1 year ago

currently do this as a work around:

 <input type="radio" <%= gig.type === type.value ? 'checked' : ''%> value="<%= type.value %>">
kraih commented 1 year ago

Done.