Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select profile if any of its choices are interacted with #729

Merged
merged 8 commits into from
May 18, 2023
17 changes: 14 additions & 3 deletions kubespawner/templates/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<div class="form-group" id="kubespawner-profiles-list">
{%- for profile in profile_list %}
{#- Wrap everything in a label tag so clicking anywhere selects the option #}
<label for="profile-item-{{ profile.slug }}" class="profile">
<label for="profile-item-{{ profile.slug }}"
class="profile js-profile-label">
<div class="radio">
<input type="radio"
name="profile"
Expand All @@ -17,8 +18,10 @@ <h3>{{ profile.display_name }}</h3>
<div>
{%- for k, option in profile.profile_options.items() %}
<div class="option">
<label for="profile-option-{{ profile.slug }}-{{ k }}">{{ option.display_name }}</label>
<select name="profile-option-{{ profile.slug }}-{{ k }}" class="form-control">
<label for="profile-option-{{ profile.slug }}-{{ k }}"
class="js-profile-option-label">{{ option.display_name }}</label>
<select name="profile-option-{{ profile.slug }}-{{ k }}"
class="form-control js-profile-option-select">
{%- for k, choice in option['choices'].items() %}
<option value="{{ k }}" {% if choice.default %}selected{% endif %}>{{ choice.display_name }}</option>
{%- endfor %}
Expand All @@ -31,3 +34,11 @@ <h3>{{ profile.display_name }}</h3>
</label>
{%- endfor %}
</div>
<script>
$('.js-profile-option-select, .js-profile-option-label').click(function() {
// we need this bit of JS to select the profile when a <select> inside is clicked.
$(this).parents('.js-profile-label')
.find('input[type=radio]')
.prop('checked', true);
});
</script>