feat(ansible): default source/playbook dropdowns to the first item
The schedule and host run forms opened their Source/Playbook <select>s on a "— choose … —" placeholder, forcing an extra click. Default them to the first item and cascade the dependent fields so the initial state is real: - Remove the placeholder options (schedules source+playbook, host source+ playbook, and the shared _playbook_options fragment). - schedules(): pass sel_source (first source, or the edited schedule's) and that source's pre-rendered playbooks so the playbook dropdown starts populated (create mode too, no longer the all-sources union). - Cascade on load/change: the source <select> fires playbook-options then (hx-on::after-settle) re-triggers the playbook <select>, which loads that playbook's variable fields. Host form drives the whole chain from a load trigger; schedule create mode loads vars via the playbook <select>'s own load trigger, while edit mode keeps its server-rendered prefill untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
{# <option> list for a playbook <select>, populated when a source is chosen.
|
||||
Returned by /ansible/playbook-options. `selected` pre-selects one (edit). #}
|
||||
<option value="">— choose playbook —</option>
|
||||
Returned by /ansible/playbook-options. `selected` pre-selects one; with none
|
||||
given the browser selects the first, so the dropdown never sits on a
|
||||
placeholder. #}
|
||||
{% for pb in playbooks %}
|
||||
<option value="{{ pb }}" {% if pb == selected %}selected{% endif %}>{{ pb }}</option>
|
||||
{% endfor %}
|
||||
|
||||
@@ -89,20 +89,21 @@
|
||||
<label>Source</label>
|
||||
<select name="source_name" required
|
||||
hx-get="/ansible/playbook-options" hx-trigger="change"
|
||||
hx-target="#sch-playbook" hx-swap="innerHTML" hx-include="this">
|
||||
<option value="">— choose source —</option>
|
||||
hx-target="#sch-playbook" hx-swap="innerHTML" hx-include="this"
|
||||
hx-on::after-settle="htmx.trigger('#sch-playbook','change')">
|
||||
{% for sd in source_data %}
|
||||
<option value="{{ sd.name }}" {% if editing and editing.source_name == sd.name %}selected{% endif %}>{{ sd.name }}</option>
|
||||
<option value="{{ sd.name }}" {% if sd.name == sel_source %}selected{% endif %}>{{ sd.name }}</option>
|
||||
{% endfor %}
|
||||
{% if not source_data %}<option value="" disabled>No Ansible sources — add one in Settings</option>{% endif %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group" style="margin-bottom:0;">
|
||||
<label>Playbook</label>
|
||||
<select name="playbook_path" id="sch-playbook" required
|
||||
hx-get="/ansible/playbook-vars?schedule=1" hx-trigger="change"
|
||||
hx-get="/ansible/playbook-vars?schedule=1"
|
||||
hx-trigger="{% if not editing %}load, {% endif %}change"
|
||||
hx-target="#sch-playbook-vars" hx-swap="innerHTML" hx-include="closest form">
|
||||
<option value="">— choose playbook —</option>
|
||||
{% for pb in all_playbooks %}
|
||||
{% for pb in sel_playbooks %}
|
||||
<option value="{{ pb }}" {% if editing and editing.playbook_path == pb %}selected{% endif %}>{{ pb }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user