Skip to content

Commit

Permalink
Fixed form errors, updated the old ones
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasdrga committed Jul 25, 2024
1 parent 7d99808 commit 9f22d63
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 34 deletions.
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);
addCloseButtonListener(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

0 comments on commit 9f22d63

Please sign in to comment.