Browse Source

inserido nova feature de input file, corrigido alguns bugs

dev
Matheo Bonucia 7 months ago
parent
commit
3a0dc022ba
  1. 67
      admin/FormGenerator.php
  2. 33
      admin/css/forms_style.css
  3. 9
      admin/js/formularios.js

67
admin/FormGenerator.php

@ -38,9 +38,10 @@ class FormGenerator
$formulario .= '</div>';
$formulario .= $this->createButtonsForms();
$formulario .= $this->showLoading();
$formulario .= $this->createJavaScript($this->formulario_js);
$formulario .= '</form></body></html>';
$formulario .= '</div></form>';
$formulario .= $this->createJavaScript($this->formulario_js);
$formulario .= '</body></html>';
return $formulario;
}
@ -227,6 +228,14 @@ class FormGenerator
$props = $elemento['propriedades'];
switch ($tipo) {
case 'file':
return '<div class="file-class"> <div class="file-label"><p>' . $elemento['text'] . '</p></div>
<label class="custom-file" for="' . $props[0]['id'] . '">
<input ' . $this->generateAttributes($props[0]) . ' />Upload
<span class="custom-file-span"></span>
</label></div>';
break;
case 'toggle':
return '<div class="toggle-bn">
<label class="switch" for="' . $props[0]['id'] . '">
@ -339,12 +348,12 @@ class FormGenerator
$attributesRemove = $this->generateAttributes($props[1]);
$botaoSelect = '<div class="select-bn">
<div ' . $attributesAdd . '>
<h3> > </h3>
<div ' . $attributesAdd . '>
<h3> &gt; </h3>
</div>
<div ' . $attributesRemove . '>
<h3>
< </h3>
&lt; </h3>
</div>
</div>';
@ -608,6 +617,39 @@ class FormGenerator
];
}
public function inputFile(
?string $class_column = 'normal',
?string $title = null,
?string $text = null,
?string $name = null,
?bool $required = false,
?array $div_open = null,
?string $div_close = null,
?bool $multiple = false,
string $accept = null,
) {
return [
'tipo-conteudo' => 'file',
'titulo' => $title,
'classe-coluna' => $class_column,
'abrir-div' => $div_open,
'fechar-div' => $div_close,
'text' => $text,
'propriedades' => [
[
'name' => $name,
'id' => $this->removeSquareBrackets($name),
'type' => 'file',
'multiple' => $multiple,
'required' => $required,
'onchange' => 'updateFileLabel(this)',
'accept' => $accept,
'style' => 'display: none;',
],
],
];
}
// Função para criar um campo de texto
private function inputPropsText($name, $value, $value_banco, $size, $maxlength, $oninput, $required, $pattern, $placeholder, $disabled, $style)
@ -784,10 +826,6 @@ class FormGenerator
public function select($title = null, $class_column = null, $name = null, $options = null, $size = null, $multiple = null)
{
if (strpos($name, '[') !== false && strpos($name, ']') !== false) {
// Remove os colchetes da string
$id = preg_replace('/[\[\]]/', '', $name);
}
return [
'tipo-conteudo' => 'normal',
'classe-coluna' => $class_column,
@ -796,7 +834,7 @@ class FormGenerator
'propriedades' => [
[
'name' => $name,
'id' => $id,
'id' => $this->removeSquareBrackets($name),
'class' => 'selecao',
'options' => $options,
'size' => $size,
@ -806,6 +844,15 @@ class FormGenerator
];
}
private function removeSquareBrackets($name)
{
if (strpos($name, '[') !== false && strpos($name, ']') !== false) {
// Remove os colchetes da string
return preg_replace('/[\[\]]/', '', $name);
}
return $name;
}
public function inputCodecs($title = null, $options = null)
{
return [

33
admin/css/forms_style.css

@ -517,6 +517,39 @@ input:checked+.slider:before {
/* garantir que fique sobre o fundo embaçado */
}
.custom-file {
padding: 6px 12px;
cursor: pointer;
color: #fff;
border-radius: 4px;
font-size: 14px;
background-color: #6e26fa;
font-weight: 501;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
height: 24px;
align-items: center;
display: flex;
}
.file-label {
border: 1px solid #6e26fa;
align-items: center;
align-self: stretch;
border-radius: 4px;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
color: #9761ff8a;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.file-class>div>p {
font-size: 14px;
margin: 0 15px;
}
@keyframes spin {
0% {
transform: rotate(0deg);

9
admin/js/formularios.js

@ -186,6 +186,15 @@ function marca_todos() {
}
}
function updateFileLabel(inputElement) {
var fileLabelParagraph =
inputElement.parentElement.parentElement.querySelector(".file-class p");
if (fileLabelParagraph) {
var fileName = inputElement.files[0].name;
fileLabelParagraph.textContent = fileName;
fileLabelParagraph.style.color = "#333";
}
}
document.addEventListener("DOMContentLoaded", function () {
// Adiciona um manipulador de eventos ao formulário
document.getElementById("form1").addEventListener("submit", function () {

Loading…
Cancel
Save