@ -8,6 +8,8 @@
< 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 >
< 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 >
form {
display: flex;
@ -83,12 +85,13 @@
< / div >
< / div >
< div class = "form-group row" >
< div class = "form-group row" >
< label class = "col-sm-3 col-form-label" for = "keywords" > Keywords< / label >
< div class = "col-sm-9" >
< input type= "text" th:field = "*{keywords}" th:value = "*{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">
< div class = "col-sm-9" >
< input name= "tags" id = "keywords" placeholder = "Introduce keywords">
< / div >
< / div >
< input type = "hidden" id = "joinedKeywords" name = "joinedKeywords" >
< div class = "form-group row" >
< label class = "col-sm-3 col-form-label" for = "sector" > Sector< / label >
@ -107,21 +110,41 @@
< / form >
< script >
function goBack() {
console.log("goBack function called");
window.history.back();
}
var tagify; // Declare tagify outside of the $(document).ready() function
$(document).ready(function() {
// Get the keywords from the Empresa object
var keywords = "[[${empresa.keywords}]]";
// Split the keywords string into an array of keywords
var keywordsArray = keywords.split(',');
// Set the value of the keywords input field
var tagifyInput = document.querySelector('input[name=tags]');
tagify = new Tagify(tagifyInput); // Initialize tagify
tagify.addTags(keywordsArray);
});
$(document).ready(function () {
$("form").on("submit", function (event) {
event.preventDefault();
var formData = $(this).serialize();
var sectorId = $('#sector').val();
formData += '& sector=' + encodeURIComponent(sectorId);
var formDataArray = $(this).serializeArray();
var tags = tagify.value.map(function(tagData) {
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({
url: '/empresa/update',
type: 'post',
data: formData,
data: $.param( formDataArray) ,
success: function (message) {
if(message === "Los datos de la empresa fue renovados con exito") {
alert("Los datos de la empresa fue renovada con exito")
@ -138,8 +161,6 @@
});
});
});
< / script >
< / body >
< / html >