Skip to content

Commit

Permalink
kontrola prvkov, či nie sú prázdne, pridávanie aj editácia funguje
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip10 committed Dec 6, 2023
1 parent fe404ac commit 8f8aa6a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
5 changes: 3 additions & 2 deletions App/Views/Admin/edit.view.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
</div>
<?php endforeach; ?>
<?php endif; ?>
<script src="../../../public/js/date-check.js"></script>
<form method="post" action="<?= $link->url('admin.save') ?>" enctype="multipart/form-data">
<form id="myForm" method="post" action="<?= $link->url('admin.save') ?>" enctype="multipart/form-data">

<input type="hidden" name="id" value="<?= @$data['post']?->getId() ?>">

Expand All @@ -42,6 +41,7 @@
<input type="date" class="form-control" name="date" id="post-date"
value="<?= $formattedDate ?>">
</div>
<div id="date-validation-message" style="color: red;"></div>

<!-- url (Zdroj) -->
<label for="post-url" class="form-label">Adresa</label>
Expand All @@ -51,3 +51,4 @@

<button type="submit" class="btn btn-primary">Uložiť</button>
</form>
<script src="../../../public/js/date-check.js"></script>
3 changes: 3 additions & 0 deletions App/Views/Home/ostatne.view.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<p>Mestská hromadná doprava.</p>
<p>Cyklochodníky</p>

<?php if ($auth->isLogged() && $auth->getLoggedUserName()) { ?>
<a href="<?= $link->url("admin.add") ?>" class="btn btn-primary">Pridaj príspevok</a>
<?php } ?>
<div class="row mb-3 p-3">
<?php
foreach ($data as $post) {
Expand Down
41 changes: 40 additions & 1 deletion public/js/date-check.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
document.getElementById('myForm').addEventListener('submit', function(event) {
// Validate the date before submitting the form
if (!validateDate()) {
if (!validateDate() || !validateText() || !validateNazov() || !validateUrl()) {
// If the date is not valid, prevent the form submission
event.preventDefault();
console.log('Form submission prevented due to an invalid date');
Expand All @@ -24,4 +24,43 @@ function validateDate() {
console.log('Invalid date');
return false;
}
}

function validateText() {
var inputText = document.getElementById('post-popis').value;
//var validationMessage = document.getElementById('text-validation-message');

if (inputText.trim() !== '') {
//validationMessage.style.display = 'none'; // Hide any previous error message
console.log('Valid text');
return true;
} else {
//validationMessage.style.display = 'block'; // Show error message
console.log('Invalid text');
return false;
}
}

function validateNazov() {
var inputText = document.getElementById('post-nazov').value;

if (inputText.trim() !== '') {
console.log('Valid nazov');
return true;
} else {
console.log('Invalid nazov');
return false;
}
}

function validateUrl() {
var inputText = document.getElementById('post-url').value;

if (inputText.trim() !== '') {
console.log('Valid url');
return true;
} else {
console.log('Invalid url');
return false;
}
}

0 comments on commit 8f8aa6a

Please sign in to comment.