Commit 368e8ed8 authored by Alfonso Rafael Solis Rangel's avatar Alfonso Rafael Solis Rangel
Browse files

funciones de normalizacion de texto

parent bb42d278
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -211,10 +211,37 @@
    <script src="/assets/js/jquery.toast.js"></script>

    <script>
        function aplicarBusquedaNormalizada(niceSelectEl){
            const input = niceSelectEl.querySelector('.nice-select-search');

            if(input){
                function normalizarTexto(texto){
                    return texto.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
                }

                input.addEventListener('keydown', function (e) {
                    if (e.key === ' ') {
                        e.stopPropagation();
                    }
                });

                input.addEventListener('input', function () {
                    const search = normalizarTexto(this.value);
                    const options = niceSelectEl.querySelectorAll('.option');

                    options.forEach(option => {
                        const optionText = normalizarTexto(option.textContent);
                        option.style.display = optionText.includes(search) ? '' : 'none';
                    });
                });
            }
        }

        // seachable
        var options = {
            searchable: true
        };

        document.addEventListener("DOMContentLoaded", function(e) {
            // default
            var els = document.querySelectorAll(".selectize");
@@ -225,6 +252,12 @@
            NiceSelect.bind(document.getElementById("subgrupo_id"), options);
            NiceSelect.bind(document.getElementById("contacto_id"), options);

            setTimeout(()=> {
                document.querySelectorAll('.nice-select').forEach(select => {
                    aplicarBusquedaNormalizada(select);
                });
            }, 100);

            document.querySelectorAll('.nice-select .current').forEach(el => {
                if (el.textContent.trim() === 'Select an option') {
                    el.textContent = 'Selecciona una opción';
@@ -285,6 +318,13 @@
            `;
            dynamicFormContainerSubgrupos.appendChild(newFormGroup);
            NiceSelect.bind(document.getElementById(newSelectSubgrupo), options);
            setTimeout(()=>{
                const nuevoNiceSelect = document.querySelector(`#${newSelectSubgrupo}`).nextElementSibling;
                if(nuevoNiceSelect && nuevoNiceSelect.classList.contains('nice-select')){
                    aplicarBusquedaNormalizada(nuevoNiceSelect);
                }
            }, 50);

            // Añadir evento de clic para eliminar
            newFormGroup.querySelector('.removeBtn').addEventListener('click', function() {
                newFormGroup.remove();
@@ -318,6 +358,13 @@
            `;
            dynamicFormContainerGrupos.appendChild(newFormGroup);
            NiceSelect.bind(document.getElementById(newSelectId), options);
            setTimeout(()=>{
                const nuevoNiceSelect = document.querySelector(`#${newSelectId}`).nextElementSibling;
                if(nuevoNiceSelect && nuevoNiceSelect.classList.contains('nice-select')){
                    aplicarBusquedaNormalizada(nuevoNiceSelect);
                }
            }, 50);

            // Añadir evento de clic para eliminar
            newFormGroup.querySelector('.removeBtn').addEventListener('click', function() {
                newFormGroup.remove();
@@ -350,6 +397,13 @@
            `;
            dynamicFormContainerContactos.appendChild(newFormGroup);
            NiceSelect.bind(document.getElementById(newSelectId), options);
            setTimeout(()=>{
                const nuevoNiceSelect = document.querySelector(`#${newSelectId}`).nextElementSibling;
                if(nuevoNiceSelect && nuevoNiceSelect.classList.contains('nice-select')){
                    aplicarBusquedaNormalizada(nuevoNiceSelect);
                }
            }, 50);
            
            // Añadir evento de clic para eliminar
            newFormGroup.querySelector('.removeBtn').addEventListener('click', function() {
                newFormGroup.remove();
+54 −1
Original line number Diff line number Diff line
<x-layout.default>
    <link rel='stylesheet' type='text/css' href='{{ Vite::asset("resources/css/nice-select2.css") }}'>
    <script src="/assets/js/alpine-mask.min.js"></script>
    <div x-data="editarLista">
    <div>
        <ul class="flex space-x-2 rtl:space-x-reverse">
            <li>
                <a href="javascript:;" class="text-primary hover:underline">Dashboard</a>
@@ -220,6 +220,32 @@
    <script src="/assets/js/jquery.toast.js"></script>

    <script>
        function aplicarBusquedaNormalizada(niceSelectEl){
            const input = niceSelectEl.querySelector('.nice-select-search');

            if(input){
                function normalizarTexto(texto){
                    return texto.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
                }

                input.addEventListener('keydown', function (e) {
                    if (e.key === ' ') {
                        e.stopPropagation();
                    }
                });

                input.addEventListener('input', function () {
                    const search = normalizarTexto(this.value);
                    const options = niceSelectEl.querySelectorAll('.option');

                    options.forEach(option => {
                        const optionText = normalizarTexto(option.textContent);
                        option.style.display = optionText.includes(search) ? '' : 'none';
                    });
                });
            }
        }

        // seachable
        var options = {
            searchable: true
@@ -234,6 +260,12 @@
            NiceSelect.bind(document.getElementById("subgrupo_id"), options);
            NiceSelect.bind(document.getElementById("contacto_id"), options);

            setTimeout(()=> {
                document.querySelectorAll('.nice-select').forEach(select => {
                    aplicarBusquedaNormalizada(select);
                });
            }, 100);

            document.querySelectorAll('.nice-select .current').forEach(el => {
                if (el.textContent.trim() === 'Select an option') {
                    el.textContent = 'Selecciona una opción';
@@ -294,6 +326,13 @@
            `;
            dynamicFormContainerSubgrupos.appendChild(newFormGroup);
            NiceSelect.bind(document.getElementById(newSelectSubgrupo), options);
            setTimeout(()=>{
                const nuevoNiceSelect = document.querySelector(`#${newSelectSubgrupo}`).nextElementSibling;
                if(nuevoNiceSelect && nuevoNiceSelect.classList.contains('nice-select')){
                    aplicarBusquedaNormalizada(nuevoNiceSelect);
                }
            }, 50);

            // Añadir evento de clic para eliminar
            newFormGroup.querySelector('.removeBtn').addEventListener('click', function() {
                newFormGroup.remove();
@@ -327,6 +366,13 @@
            `;
            dynamicFormContainerGrupos.appendChild(newFormGroup);
            NiceSelect.bind(document.getElementById(newSelectId), options);
            setTimeout(()=>{
                const nuevoNiceSelect = document.querySelector(`#${newSelectId}`).nextElementSibling;
                if(nuevoNiceSelect && nuevoNiceSelect.classList.contains('nice-select')){
                    aplicarBusquedaNormalizada(nuevoNiceSelect);
                }
            }, 50);

            // Añadir evento de clic para eliminar
            newFormGroup.querySelector('.removeBtn').addEventListener('click', function() {
                newFormGroup.remove();
@@ -359,6 +405,13 @@
            `;
            dynamicFormContainerContactos.appendChild(newFormGroup);
            NiceSelect.bind(document.getElementById(newSelectId), options);
            setTimeout(()=>{
                const nuevoNiceSelect = document.querySelector(`#${newSelectId}`).nextElementSibling;
                if(nuevoNiceSelect && nuevoNiceSelect.classList.contains('nice-select')){
                    aplicarBusquedaNormalizada(nuevoNiceSelect);
                }
            }, 50);

            // Añadir evento de clic para eliminar
            newFormGroup.querySelector('.removeBtn').addEventListener('click', function() {
                newFormGroup.remove();