Skip to content

Commit

Permalink
VSVGVQ-158 info text for alias fields and show urls if filled in
Browse files Browse the repository at this point in the history
  • Loading branch information
stejes committed Aug 28, 2018
1 parent 2a1fe6c commit 839cd44
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
35 changes: 35 additions & 0 deletions public/js/handleAliases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
$("#form_companyName").focusout(function () {
let slug = slugify($("#form_companyName").val());
if ($("#form_aliasNl").val().trim() === '') {
$("#form_aliasNl").val(slug).trigger("change");

}
if ($("#form_aliasFr").val().trim() === '') {
let slug = slugify($("#form_companyName").val());
$("#form_aliasFr").val(slug).trigger("change");
}
});

$("#form_aliasNl").on("change paste keyup input", function () {
handleNlUrlState();
});

$("#form_aliasFr").on("change paste keyup input", function () {
handleFrUrlState();
});

function handleNlUrlState() {
if ($("#form_aliasNl").val().trim() != '') {
$("#form_alias_url_nl").text('www.degroteverkeersquiz.be/quiz/'+$("#form_aliasNl").val());
} else {
$("#form_alias_url_nl").text('');
}
}

function handleFrUrlState() {
if ($("#form_aliasFr").val().trim() != '') {
$("#form_alias_url_fr").text('www.quizdelaroute.be/quiz/'+$("#form_aliasFr").val());
} else {
$("#form_alias_url_fr").text('');
}
}
4 changes: 2 additions & 2 deletions src/Company/Forms/CompanyFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)

$builder
->add(
'name',
'companyName',
TextType::class,
[
'data' => $company ? $company->getName()->toNative() : null,
Expand Down Expand Up @@ -111,7 +111,7 @@ public function newCompanyFromData(
): Company {
return new Company(
$uuidFactory->uuid4(),
new NotEmptyString($data['name']),
new NotEmptyString($data['companyName']),
new PositiveNumber($data['nrOfEmployees']),
new TranslatedAliases(
new TranslatedAlias(
Expand Down
12 changes: 5 additions & 7 deletions templates/accounts/register.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@
<label for="form_aliasNl">{% trans %}Alias.dutch{% endtrans %}</label>
{{ form_widget(form.aliasNl) }}
{{ form_errors(form.aliasNl) }}
<small id="form_alias_url_nl" class="form-text text-muted"></small>
</div>
<div class="col-sm-6">
<label for="form_aliasFr">{% trans %}Alias.french{% endtrans %}</label>
{{ form_widget(form.aliasFr) }}
{{ form_errors(form.aliasFr) }}
<small id="form_alias_url_fr" class="form-text text-muted"></small>
</div>
</div>
<small id="form_alias_info" class="form-text text-muted">{% trans %}
Field.alias.info{% endtrans %}</small>
</div>

<div class="form-group">
Expand All @@ -98,11 +102,5 @@
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('js/slugify.js') }}"></script>
<script>
$("#form_companyName").focusout(function () {
let slug = slugify($("#form_companyName").val());
$("#form_aliasNl").val(slug);
$("#form_aliasFr").val(slug);
});
</script>
<script src="{{ asset('js/handleAliases.js') }}"></script>
{% endblock %}
20 changes: 15 additions & 5 deletions templates/companies/add.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<div class="form-group">
<div class="row">
<div class="col-6">
<label for="form_email">{% trans %}Company.name{% endtrans %}</label>
{{ form_widget(form.name) }}
{{ form_errors(form.name) }}
<label for="form_companyName">{% trans %}Company.name{% endtrans %}</label>
{{ form_widget(form.companyName) }}
{{ form_errors(form.companyName) }}
</div>
<div class="col-6">
<label for="form_nrOfEmployees">{% trans %}Employees{% endtrans %}</label>
Expand All @@ -26,16 +26,20 @@
<div class="form-group">
<div class="row">
<div class="col-6">
<label for="form_firstName">{% trans %}Alias.dutch{% endtrans %}</label>
<label for="form_aliasNl">{% trans %}Alias.dutch{% endtrans %}</label>
{{ form_widget(form.aliasNl) }}
{{ form_errors(form.aliasNl) }}
<small id="form_alias_url_nl" class="form-text text-muted"></small>
</div>
<div class="col-6">
<label for="form_lastName">{% trans %}Alias.french{% endtrans %}</label>
<label for="form_aliasFr">{% trans %}Alias.french{% endtrans %}</label>
{{ form_widget(form.aliasFr) }}
{{ form_errors(form.aliasFr) }}
<small id="form_alias_url_fr" class="form-text text-muted"></small>
</div>
</div>
<small id="form_alias_info" class="form-text text-muted">{% trans %}
Field.alias.info{% endtrans %}</small>
</div>

<div class="form-group">
Expand All @@ -47,3 +51,9 @@
</div>
{{ form_end(form) }}
{% endblock %}

{% block javascripts %}
{{ parent() }}
<script src="{{ asset('js/slugify.js') }}"></script>
<script src="{{ asset('js/handleAliases.js') }}"></script>
{% endblock %}
1 change: 1 addition & 0 deletions translations/messages.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Field.year.empty: L'année est obligatoire.
Field.year.min: L'année doit être {{ limit }} ou plus.
Field.year.max: L'année doit être {{ limit }} ou moins.
Field.login.warning: __Als je dit veld wijzigt moet je opnieuw inloggen.
Field.alias.info: __Via deze url spelen je collega’s de quiz. Enkel alfanumerieke tekens en een koppelteken zijn toegestaan.

#Flash
Registration.error: Une erreur est survenue lors de votre inscription. Réessayez à nouveau.
Expand Down
1 change: 1 addition & 0 deletions translations/messages.nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Field.year.empty: 'Het jaar mag niet leeg zijn.'
Field.year.min: 'Het jaar moet {{ limit }} of groter zijn.'
Field.year.max: 'Het jaar moet {{ limit }} of kleiner zijn.'
Field.login.warning: 'Als je dit veld wijzigt moet je opnieuw inloggen.'
Field.alias.info: 'Via deze url spelen je collega’s de quiz. Enkel alfanumerieke tekens en een koppelteken zijn toegestaan.'

#Flash messages
Registration.error: 'Er ging iets mis bij het wegschrijven van de gegevens, gelieve opnieuw te proberen.'
Expand Down

0 comments on commit 839cd44

Please sign in to comment.