Skip to content

Commit

Permalink
fix(contact): Improve paste from linkedin
Browse files Browse the repository at this point in the history
Fill form contact name
  • Loading branch information
gnovaro committed Mar 20, 2024
1 parent 8a61f58 commit c0bb522
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
37 changes: 29 additions & 8 deletions resources/views/contact/contact_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,23 @@ class="form-control form-control-lg">
</div>
@push('scripts')
<script>
// Función para convertir la primera letra de una cadena en mayúscula
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
function isEmpty(str) {
return (!str || str.trim().length === 0);
}
function removeLastWord(str) {
return str.replace(/\s\S*$/, '');
}
$(document).ready(function() {
$('#contact_linkedin').on('paste', function(event) {
setTimeout(() => {
let url = $(this).val();
function updateNameFromLinkedIn(url) {
if (url) {
let matches = url.match(/linkedin\.com\/in\/([^\/]+)\//);
if (matches && matches[1]) {
Expand All @@ -118,27 +131,35 @@ class="form-control form-control-lg">
nameParts.forEach(function(part, index) {
if (index === 0) {
firstName += part.charAt(0).toUpperCase() + part.slice(1).toLowerCase(); // Convertir primera letra en mayúscula
firstName += capitalizeFirstLetter(part); // Convertir primera letra en mayúscula
} else {
if (index === nameParts.length - 1) {
// Última parte, eliminar cualquier hash alfanumérico
lastName += part.replace(/[0-9a-fA-F]+$/, '').charAt(0).toUpperCase() + part.slice(1).toLowerCase();
lastName += part.replace(/[0-9a-fA-F]+$/, '').trim();
} else {
lastName += part.charAt(0).toUpperCase() + part.slice(1).toLowerCase(); // Convertir primera letra en mayúscula
lastName += capitalizeFirstLetter(part); // Convertir primera letra en mayúscula
}
lastName += ' ';
}
});
// Eliminar espacio adicional al final del apellido
lastName = lastName.trim();
// Eliminar espacio adicional al final del apellido, remueve la ultima palabra si contiene un numero
lastName = removeLastWord(lastName.trim());
// Asignar valores a los campos de nombre y apellido
$('#contact_first_name').val(firstName);
$('#contact_last_name').val(lastName);
}
}
}
$('#contact_linkedin').on('paste change', function(event) {
setTimeout(() => {
let url = $('#contact_linkedin').val();
updateNameFromLinkedIn(url);
}, 0);
});
});
</script>
@endpush
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

const APP_VERSION = '3.9.3';
const APP_VERSION = '3.9.4';

0 comments on commit c0bb522

Please sign in to comment.