@ -8,6 +8,8 @@
< script src = "https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" > < / script >
< script src = "https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" > < / script >
< script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js" > < / script >
< script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js" > < / script >
< link rel = "stylesheet" type = "text/css" th:href = "@{/top.css}" >
< link rel = "stylesheet" type = "text/css" th:href = "@{/top.css}" >
< link rel = "stylesheet" href = "https://unpkg.com/@yaireo/tagify/dist/tagify.css" >
< script src = "https://unpkg.com/@yaireo/tagify" > < / script >
< style >
< style >
form {
form {
display: flex;
display: flex;
@ -71,7 +73,7 @@
< div class = "form-group row" >
< div class = "form-group row" >
< label class = "col-sm-3 col-form-label" for = "correo" > Correo< / label >
< label class = "col-sm-3 col-form-label" for = "correo" > Correo< / label >
< div class = "col-sm-9" >
< div class = "col-sm-9" >
< input type = " text" th:field = "*{correo}" required pattern = "[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$ " title = "Entra en correo valido." class = "form-control" id = "correo" >
< input type = " email" th:field = "*{correo}" required minlength = "5" maxlength = "100 " title = "Entra en correo valido." class = "form-control" id = "correo" >
< / div >
< / div >
< / div >
< / div >
@ -85,9 +87,11 @@
< div class = "form-group row" >
< div class = "form-group row" >
< label class = "col-sm-3 col-form-label" for = "keywords" > Keywords< / label >
< label class = "col-sm-3 col-form-label" for = "keywords" > Keywords< / label >
< div class = "col-sm-9" >
< div class = "col-sm-9" >
< input type= "text" th:field = "*{keywords}" required pattern = "([a-zA-Z0-9]+,)*[a-zA-Z0-9]+" title = "Los keywords tiene que ser separados por una ," class = "form-control" id = " keywords">
< input name= "tags" id = "keywords" placeholder = "Introduce keywords">
< / div >
< / div >
< / div >
< / div >
< input type = "hidden" id = "joinedKeywords" name = "joinedKeywords" >
< div class = "form-group row" >
< div class = "form-group row" >
< label class = "col-sm-3 col-form-label" for = "sector" > Sector< / label >
< label class = "col-sm-3 col-form-label" for = "sector" > Sector< / label >
@ -106,21 +110,38 @@
< / form >
< / form >
< script >
< script >
var tagify; // Declare tagify outside of the $(document).ready() function
$(document).ready(function() {
// Set the value of the keywords input field
var tagifyInput = document.querySelector('input[name=tags]');
tagify = new Tagify(tagifyInput); // Initialize tagify
});
function goBack() {
function goBack() {
console.log("goBack function called");
console.log("goBack function called");
window.history.back();
window.history.back();
}
}
$(document).ready(function () {
$(document).ready(function () {
$("form").on("submit", function (event) {
$("form").on("submit", function (event) {
event.preventDefault();
event.preventDefault();
var formData = $(this).serialize();
var formDataArray = $(this).serializeArray();
var sectorId = $('#sector').val();
var tags = tagify.value.map(function(tagData) {
formData += '& empresa=' + encodeURIComponent(sectorId);
return tagData.value ? tagData.value.trim() : null;
}).filter(function(tag) { return tag; });
// Convert the tags array to a comma-separated string
var joinedKeywords = tags.join(',');
formDataArray.push({name: 'empresa', value: $('#sector').val()});
formDataArray.push({name: 'joinedKeywords', value: joinedKeywords});
$.ajax({
$.ajax({
url: '/empresa/save',
url: '/empresa/save',
type: 'post',
type: 'post',
data: formData,
data: $.param( formDataArray) ,
success: function (message) {
success: function (message) {
if(message === "La empresa fue guardado con exito") {
if(message === "La empresa fue guardado con exito") {
alert("La empresa fue guardado con exito")
alert("La empresa fue guardado con exito")
@ -140,8 +161,6 @@
});
});
});
});
});
});
< / script >
< / script >
< / body >
< / body >
< / html >
< / html >