Skip to content

Commit

Permalink
[#2245] Changed checkbox template and added multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
jiromaykin committed Mar 24, 2024
1 parent c844fa4 commit a7aca0b
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,74 @@
{% extends 'master.html' %}
{% load i18n static form_tags card_tags grid_tags solo_tags %}
{% load i18n static form_tags card_tags grid_tags solo_tags icon_tags %}

{% block content %}
<div class="registration-grid">
{% render_grid %}
{% render_column span=9 %}
{% render_card tinted=True %}
{% render_grid %}
{% render_column start=5 span=5 %}
{% get_solo 'configurations.SiteConfiguration' as config %}
<h1 class="h1">{% trans "Registratie voltooien" %}</h1><br>
{% if config.registration_text %}<p class="p">{{ config.registration_text|urlize|linebreaksbr }}</p><br>{% endif %}
{% if config.registration_text %}<p class="p">{{ config.registration_text|urlize|linebreaksbr }}</p>{% endif %}
<form method="POST" id="necessary-form" action="{{ request.get_full_path }}" class="form" novalidate>
{% csrf_token %}

{% for field in form.fields %}
{% autorender_field form field %}
{% endfor %}
{% if form.first_name %}
{% input form.first_name %}
{% endif %}

<div class="form__control">
{# pseudo checkbox for notifications that cannot be disabled #}
<div class="checkbox">
<span role="checkbox" aria-disabled="true" aria-checked="true" class="checkbox__input checkbox__pseudo checkbox__input--disabled" aria-labelledby="id_cases_notifications_action_required" tabindex="0"></span>
<span class="checkbox__label checkbox__pseudo-label" id="id_cases_notifications_action_required">{% trans "Zaaknotificaties - actie is nodig" %}</span>
<p class="p">{% trans "E-mailnotificaties wanneer er actie nodig is voor een zaak (kan niet uitgeschakeld worden)" %}</p>
</div>
</div>
{% if form.infix %}
{% input form.infix %}
{% endif %}

{% form_actions primary_icon='arrow_forward' primary_text="Verzenden" %}
{% if form.last_name %}
{% input form.last_name %}
{% endif %}

{% if form.email %}
{% input form.email %}
{% endif %}

{% if form.invite %}
{% input form.invite no_label=True %}
{% endif %}

<h3 class="h3">Notificatie voorkeuren</h3>

{# Start of multiple checkbox fields #}
<ul class="choice-list choice-list-multiple">

{% if form.cases_notifications %}
<li class="choice-list-multiple__item">
<div class="choice-list-multiple__content">
{% checkbox form.cases_notifications %}
</div>
</li>
{% endif %}

{% if form.messages_notifications %}
<li class="choice-list-multiple__item">
<div class="choice-list-multiple__content">
{% checkbox form.messages_notifications %}</div>
</li>
{% endif %}

{% if form.plans_notifications %}
<li class="choice-list-multiple__item">
<div class="choice-list-multiple__content">
{% checkbox form.plans_notifications %}</div>
</li>
{% endif %}
</ul>
{# End of multiple checkbox fields #}

{# Info on notifications that cannot be disabled #}
<div class="choice-list__information">
<p class="choice-list-multiple__heading-4">{% icon icon="check" outlined=True %} {% trans "Zaaknotificaties - actie is nodig" %}</p>
<p class="choice-list__p">{% trans "E-mailnotificaties wanneer er actie nodig is voor een zaak (kan niet uitgeschakeld worden)" %}</p>
</div>

{% form_actions primary_icon='east' primary_text="Voltooi registratie" fullwidth=True %}
</form>
{% endrender_card %}
{% endrender_column %}
{% endrender_grid %}
{% endrender_column %}
{% endrender_grid %}
</div>
{% endblock content %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<div class="form__control">
<div class="checkbox">
{{ field|addclass:"checkbox__input" }}
{% if not no_label %}<label class="checkbox__label" for="id_{{ field.name }}">{{ field.label }}</label>{% endif %}
{% if field.help_text %}
<p class="p{{ help_extra_cls }}">{{ field.help_text }}</p>
{% if not no_label %}<label class="checkbox__label" for="id_{{ field.name }}">{{ field.label }}
{% if field.help_text %}
<p class="choice-list__p">{{ field.help_text }}</p>
{% endif %}</label>
{% endif %}

{% if field.errors %}
Expand Down
35 changes: 35 additions & 0 deletions src/open_inwoner/js/components/form/ChoiceListMultiple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export class ChoiceListMultiple {
static selector = '.choice-list-multiple .choice-list-multiple__item'

constructor(listitem) {
this.listitem = listitem
this.checkbox = listitem.querySelector(
'.choice-list-multiple input[type="checkbox"]'
)
this.label = listitem.querySelector(
'.choice-list-multiple .choice-list-multiple__item .checkbox__label'
)
// Add 'selected' parentclass if checkbox is already checked onLoad
if (this.checkbox.checked) {
this.listitem.classList.add('selected')
}
// If selector exists
this.listitem.addEventListener(
'click',
this.toggleChoiceItemBorder.bind(this)
)
}

toggleChoiceItemBorder() {
if (this.checkbox.checked) {
this.listitem.classList.add('selected')
} else {
this.listitem.classList.remove('selected')
}
}
}

// Apply toggleChoiceItemBorder to each element matching the selector
document
.querySelectorAll(ChoiceListMultiple.selector)
.forEach((listitem) => new ChoiceListMultiple(listitem))
1 change: 1 addition & 0 deletions src/open_inwoner/js/components/form/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './FileInput'
import './ChoiceListMultiple'
import './ChoiceListSingle'
import './DisableContactFormButton'
1 change: 0 additions & 1 deletion src/open_inwoner/scss/components/Filter/Filter.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
}

.divider {
background-color: yellow;
border: red solid 5px !important;
&--small {
display: none;
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/scss/components/Form/Checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
width: var(--font-line-height-body-small);
height: var(--font-line-height-body-small);
border: var(--border-width) solid var(--color-gray-dark);
border-radius: 1px; // intended-var-change.
border-radius: var(--border-radius);
background-color: var(--color-white);
}

Expand Down
121 changes: 120 additions & 1 deletion src/open_inwoner/scss/components/Form/ChoiceList.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@
padding: var(--spacing-large);
}

/// Single selection radiobutton

input[type='radio'] {
/// Display for accessibility
appearance: none;
opacity: 0;
padding: 0;
margin: 0;
width: 0;
}

&__label:before {
Expand Down Expand Up @@ -81,4 +86,118 @@
content: '\e876';
line-height: var(--font-size-body);
}

&__information {
border-bottom: 1px solid var(--color-gray-light);
border-top: 1px solid var(--color-gray-light);
margin: var(--spacing-large) 0;
padding: var(--spacing-large) 0;
max-width: var(--form-width);

.choice-list__p {
margin: var(--spacing-large) 0 0 0;
}
}

/// Multiple selection checkbox

&-multiple {
list-style: none;

&__heading-4 {
color: var(--color-black);
font-family: var(--font-family-heading);
font-size: var(--font-size-heading-4);
margin: 0;

[class*='icons'] {
font-size: var(--font-size-body);
vertical-align: text-top;
}
}

.form__control {
width: 100%;
}
}

&-multiple__item {
border: var(--border-width-thin) solid var(--color-white);
}

&-multiple__item label {
cursor: pointer;
}

&-multiple__content {
border-radius: var(--border-radius);
display: flex;
padding: 0;
width: 100%;
max-width: var(--form-width);

& .checkbox {
// reversing the order
display: flex;
flex-direction: row;
padding: var(--spacing-large);

& .checkbox__label {
padding-left: 0;
padding-right: calc(2 * var(--gutter-width));
position: relative;
width: 100%;
}
}

.checkbox .checkbox__label:before {
border: var(--border-width) solid var(--color-gray-dark);
border-radius: var(--border-radius);
top: 50%;
transform: translateX(-50%) translateY(-50%);
left: auto;
right: 0;
}

.checkbox .checkbox__input:checked ~ .checkbox__label:before {
background-color: var(--color-white);
border: var(--border-width) solid var(--color-accent);
color: var(--color-accent);
left: auto;
right: 0;
}
}

&-multiple__data {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
flex-direction: row-reverse;
width: 100%;
}

&-multiple__item input[type='checkbox'] {
appearance: none;
opacity: 0;
padding: 0;
margin: 0;
width: 0;
}

&-multiple__item input[type='checkbox'] + &-multiple__data::before {
content: '';
display: inline-block;
width: 20px;
height: 20px;
border: 2px solid #888;
margin-right: 10px;
vertical-align: middle;
}

&-multiple__item.selected {
// Parent styling
border: 1px solid var(--color-accent);
border-radius: var(--border-radius);
}
}
2 changes: 1 addition & 1 deletion src/open_inwoner/scss/components/Form/Input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-webkit-appearance: none;

/// Border.
border: 1px solid var(--color-mute);
border: 1px solid var(--color-gray);
border-radius: var(--border-radius);

/// Dimensions.
Expand Down
51 changes: 29 additions & 22 deletions src/open_inwoner/templates/pages/profile/notifications.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
{% extends 'master.html' %}
{% load i18n l10n form_tags %}
{% load i18n l10n grid_tags form_tags icon_tags button_tags %}

{% block content %}
<h1 class="h1" id="title">
{% trans "Ontvang berichten over" %}
</h1>
<p class="p">
{% trans "Kies voor welk onderwerp je meldingen wilt ontvangen" %}
</p>
<h1 class="h1" id="title">
{% trans "Ontvang berichten over" %}
</h1>
<p class="p">
{% trans "Kies voor welk onderwerp je meldingen wilt ontvangen" %}
</p>

<form method="POST" id="change-notifications" action="{% url 'profile:notifications' %}" class="form" novalidate>
{% csrf_token %}
{% render_grid %}
{% render_column start=0 span=6 %}

{% for field in form.fields %}
{% autorender_field form field %}
{% endfor %}
<form method="POST" id="change-notifications" action="{% url 'profile:notifications' %}" class="form" novalidate>
{% csrf_token %}

<div class="form__control">
{# pseudo checkbox for notifications that cannot be disabled #}
<div class="checkbox">
<span role="checkbox" aria-disabled="true" aria-checked="true" class="checkbox__input checkbox__pseudo checkbox__input--disabled" aria-labelledby="id_cases_notifications_action_required" tabindex="0"></span>
<span class="checkbox__label checkbox__pseudo-label" id="id_cases_notifications_action_required">{% trans "Zaaknotificaties - actie is nodig" %}</span>
<p class="p">{% trans "E-mailnotificaties wanneer er actie nodig is voor een zaak (kan niet uitgeschakeld worden)" %}</p>
</div>
</div>
{% for field in form.fields %}
{% autorender_field form field %}
{% endfor %}

{% form_actions primary_text=_("Opslaan") primary_icon="arrow_forward" secondary_href='profile:detail' secondary_text=_('Terug') secondary_icon_position="before" secondary_icon='arrow_backward' %}
</form>
<div class="choice-list choice-list-multiple">
{# Info on notifications that cannot be disabled #}
<div class="choice-list__information">
<p class="choice-list-multiple__heading-4">{% icon icon="check" outlined=True %} {% trans "Zaaknotificaties - actie is nodig" %}</p>
<p class="choice-list__p">{% trans "E-mailnotificaties wanneer er actie nodig is voor een zaak (kan niet uitgeschakeld worden)" %}</p>
</div>
</div>

<div class="form__actions form__actions--fullwidth">
{% button text="Sla wijzigingen op" primary=True type="submit" form_id="profile-edit" %}
{% button href="profile:detail" icon="west" text=_("Terug naar Mijn profiel") icon_outlined=True transparent=True %}
</div>
</form>

{% endrender_column %}
{% endrender_grid %}
{% endblock content %}

0 comments on commit a7aca0b

Please sign in to comment.