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

ECO-294/Form-errors #172

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions app/assets/javascripts/autoform_form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
$(document).ready(function() {
var autoformError = $('#autoform-error').get(0);
if (autoformError) {
autoform.addCloseButtonListener(autoformError);

var emailInputField = $('#autoform-email').get(0);
emailInputField.addEventListener('click', function (){
autoform.removeErrors(autoformError)
});

var domainInputField = $('#autoform-domain').get(0);
domainInputField.addEventListener('click', function (){
autoform.removeErrors(autoformError)
});
}

$('#autoform-form').submit(function() {
if ($('#autoform-email').val() == '' || $('#autoform-domain').val() == '') {
$('#autoform-form-sent').hide();
Expand Down Expand Up @@ -29,33 +44,19 @@ $(document).ready(function() {
return true;
}
});

var autoformError = $('#autoform-error').get(0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuchal konkretne tato cast, ktora hladala na kazdej pagy autoform classy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ale ved to by nemalo vadit nie? Nenajde tak nie je problem.

addCloseButtonListener(autoformError);
Copy link
Contributor Author

@tomasdrga tomasdrga Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuchal chcel som označiť tento riadok, keď sa nenájde autoformError z predchádzajúceho riadku nič sa nestane, no keď sa potom posunie do funkcie addCloseButtonListener(autoformError);, tak to zlyhá na var closeButton = node.querySelector('.alert .close'); , preto sa toto teraz udeje iba keď sa nájde autoformError


var emailInputField = $('#autoform-email').get(0);
emailInputField.addEventListener('click', function (){
removeErrors(autoformError)
});

var domainInputField = $('#autoform-domain').get(0);
domainInputField.addEventListener('click', function (){
removeErrors(autoformError)
});
});

function addCloseButtonListener(node) {
var closeButton = node.querySelector('.alert .close');
closeButton.addEventListener("click", function (){
removeErrors(node);
});
}

function removeErrors(node) {
$('#autoform-email').parent('.form-group').removeClass('has-error');
$('#autoform-domain').parent('.form-group').removeClass('has-error');
$('#' + node.id).hide();
}



var autoform = {
addCloseButtonListener: function(node) {
var closeButton = node.querySelector('.alert .close');
closeButton.addEventListener("click", function (){
autoform.removeErrors(node);
});
},

removeErrors: function(node) {
$('#autoform-email').parent('.form-group').removeClass('has-error');
$('#autoform-domain').parent('.form-group').removeClass('has-error');
$('#' + node.id).hide();
}
};
19 changes: 19 additions & 0 deletions app/assets/javascripts/consultations_form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
$(document).ready(function() {
var consultationsError = $('#consultations-error').get(0);
if (consultationsError) {
consultations.addCloseButtonListener(consultationsError);

var emailInputField = $('#consultations-email').get(0);
emailInputField.addEventListener('click', function (){
$('#' + consultationsError.id).hide();
});
}

$('#consultations-form').submit(function() {
if ($('#consultations-email').val() == '') {
$('#consultations-sent').hide();
Expand All @@ -18,3 +28,12 @@ $(document).ready(function() {
}
});
});

var consultations = {
addCloseButtonListener: function(node) {
var closeButton = node.querySelector('.alert .close');
closeButton.addEventListener("click", function (){
$('#' + node.id).hide();
});
}
};
24 changes: 24 additions & 0 deletions app/assets/javascripts/datahub_form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
$(document).ready(function() {
var datahubError = $('#datahub-error').get(0);
if (datahubError) {
datahub.addCloseButtonListener(datahubError);

var emailInputField = $('#datahub-email').get(0);
emailInputField.addEventListener('click', function (){
datahub.removeErrors(datahubError);
});
}

$('#datahub-form').submit(function() {
if ($('#datahub-email').val() == '') {
$('#datahub-form-sent').hide();
Expand All @@ -18,3 +28,17 @@ $(document).ready(function() {
}
});
});

var datahub = {
addCloseButtonListener: function(node) {
var closeButton = node.querySelector('.alert .close');
closeButton.addEventListener("click", function (){
datahub.removeErrors(node);
});
},

removeErrors: function(node) {
$('#datahub-email').parent('.form-group').removeClass('has-error');
$('#' + node.id).hide();
}
};
25 changes: 25 additions & 0 deletions app/assets/javascripts/slovensko_sk_api_form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
$(document).ready(function() {
var skApiError = $('#sk-api-error').get(0);
if (skApiError) {
slovensko_sk_api.addCloseButtonListener(skApiError);

var emailInputField = $('#sk-api-email').get(0);
emailInputField.addEventListener('click', function (){
slovensko_sk_api.removeErrors(skApiError);
});
}

$('#sk-api-form').submit(function() {
if ($('#sk-api-email').val() == '') {
$('#sk-api-form-sent').hide();
Expand All @@ -18,3 +28,18 @@ $(document).ready(function() {
}
});
});


var slovensko_sk_api = {
addCloseButtonListener: function(node) {
var closeButton = node.querySelector('.alert .close');
closeButton.addEventListener("click", function (){
slovensko_sk_api.removeErrors(node);
});
},

removeErrors: function(node) {
$('#sk-api-email').parent('.form-group').removeClass('has-error');
$('#' + node.id).hide();
}
};
11 changes: 9 additions & 2 deletions app/views/services/consultations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@
<p class="lead">Nechajte nám Váš emailový kontakt alebo nám napíšte na <a href="mailto:[email protected]">[email protected]</a>.</p>

<div id="consultations-error" style="display: none;">
<%= render 'services/share/flash_message', {type: :alert, message: 'Vyplňte prosím email a skúste znova.'} %>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" aria-label="Close"><span aria-hidden="true" class="error">&times;</span></button>
<%= 'Vyplňte prosím email a skúste znova.' %>
</div>
</div>
<div id="consultations-form-sent" style="display: none;">
<%= render 'services/share/flash_message', {type: :notice, message: 'Ďakujeme, za Váš záujem. Budeme Vás kontaktovať cez zadaný email.'} %>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true" class="success">&times;</span>
</button>
<%= 'Ďakujeme, za Váš záujem. Budeme Vás kontaktovať cez zadaný email.' %>
</div>
</div>

<iframe name="form-result" style="display: none;"></iframe>
Expand Down
11 changes: 9 additions & 2 deletions app/views/services/datahub/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,17 @@
</p>

<div id="datahub-error" style="display: none;">
<%= render 'services/share/flash_message', {type: :alert, message: 'Vyplňte prosím email a skúste znova.'} %>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" aria-label="Close"><span aria-hidden="true" class="error">&times;</span></button>
<%= 'Vyplňte prosím email a skúste znova.' %>
</div>
</div>
<div id="datahub-form-sent" style="display: none;">
<%= render 'services/share/flash_message', {type: :notice, message: 'Ďakujeme, za Váš záujem. Budeme Vás kontaktovať cez zadaný email.'} %>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true" class="success">&times;</span>
</button>
<%= 'Ďakujeme, za Váš záujem. Budeme Vás kontaktovať cez zadaný email.' %>
</div>
</div>

<iframe name="form-result" style="display: none;"></iframe>
Expand Down
11 changes: 9 additions & 2 deletions app/views/services/slovensko_sk_api/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,17 @@
</p>

<div id="sk-api-error" style="display: none;">
<%= render 'services/share/flash_message', {type: :alert, message: 'Vyplňte prosím email a skúste znova.'} %>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" aria-label="Close"><span aria-hidden="true" class="error">&times;</span></button>
<%= 'Vyplňte prosím email a skúste znova.' %>
</div>
</div>
<div id="sk-api-form-sent" style="display: none;">
<%= render 'services/share/flash_message', {type: :notice, message: 'Ďakujeme, za Váš záujem. Budeme Vás kontaktovať cez zadaný email.'} %>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true" class="success">&times;</span>
</button>
<%= 'Ďakujeme, za Váš záujem. Budeme Vás kontaktovať cez zadaný email.' %>
</div>
</div>

<iframe name="form-result" style="display: none;"></iframe>
Expand Down
Loading