Try to fix textarea

This commit is contained in:
Kilian Hofmann 2024-05-17 13:54:09 +02:00
parent a8fc530308
commit fa372fdeb8
3 changed files with 89 additions and 9 deletions

View File

@ -1,3 +1,30 @@
<style>
#comment {
resize: none;
overflow: hidden;
}
#comment-count {
right: 3px;
bottom: 0;
}
@supports selector(:has(html)) {
.was-validated .position-relative:has(:invalid)~.invalid-feedback {
display: block;
}
.was-validated :invalid~.invalid-feedback {
display: none !important;
}
}
@supports not selector(:has(html)) {
.was-validated :invalid~#comment-count {
display: none;
}
}
</style>
<form action="comment.php" method="post" class="needs-validation row m-0" novalidate>
<div class="col">
<h4 class="mb-3">Leave a Comment!</h4>
@ -15,8 +42,11 @@
</div>
<div class="mb-3">
<div class="position-relative">
<textarea class="form-control" id="comment" name="comment" rows="3" maxlength="250" required placeholder="Comment here"></textarea>
<small class="text-muted position-absolute" id="comment-count" style="right: 20px; bottom: 0;">
<textarea class="form-control" id="comment" name="comment" maxlength="250" required placeholder="Comment here"></textarea>
<div class="invalid-feedback">
Please enter text.
</div>
<small class="text-muted position-absolute" id="comment-count">
0/250
</small>
</div>

View File

@ -1,10 +1,10 @@
"use strict";
document.addEventListener("DOMContentLoaded", () => {
const handler = (event) => {
console.log(event.target);
const length = event.target.value.length;
const maxLength = event.target.maxLength;
const handlerCounter = (event) => {
const comment = event.target;
const length = comment.value.length;
const maxLength = comment.maxLength;
const counter = document.getElementById("comment-count");
counter.innerText = `${length}/${maxLength}`;
@ -18,10 +18,26 @@ document.addEventListener("DOMContentLoaded", () => {
}
};
const addValidation = () => {
const textarea = document.getElementById("comment");
const handlerSize = () => {
const scroll = window.scrollY;
const comment = document.getElementById("comment");
const counter = document.getElementById("comment-count");
const commentHeight = comment.clientHeight;
const counterHeight = counter.clientHeight;
textarea.addEventListener("keyup", handler);
if (commentHeight + 0.5 * counterHeight < comment.scrollHeight) {
comment.style.height = `${comment.scrollHeight + counterHeight}px`;
}
};
const addValidation = () => {
const comment = document.getElementById("comment");
const counter = document.getElementById("comment-count");
comment.style.height = `${comment.scrollHeight + counter.style.height}px`;
comment.addEventListener("input", handlerCounter);
comment.addEventListener("input", handlerSize);
window.addEventListener("resize", handlerSize);
};
addValidation();

34
tasks/random/arrays.php Normal file
View File

@ -0,0 +1,34 @@
<?php
include_once "../../base/errors.php";
include_once "../../base/headers.php";
Headers::html();
$personen = array("Felix", "Berta", "Dalia", "Cecil", "Axel", "Elmar");
$toFind = "Cecil";
$zahlen = array(4, 7, 3, 10, 8, 1, 5);
foreach ($personen as $key => $name) {
if ($name === $toFind) {
echo "$name at $key";
break;
}
}
?>
<br />
<?php
$max = 0;
$maxKey = 0;
foreach ($zahlen as $key => $value) {
if ($value > $max) {
$max = $value;
$maxKey = $key;
}
}
echo "$max at $maxKey";
for ($i = 0; $i < 10; $i++) {
echo "$i<br/>";
}
echo "AFTER: $i<br/>";