Skip to content

Commit

Permalink
Stock Symbols: input not working for single element (#2915)
Browse files Browse the repository at this point in the history
relates to xibosignage/xibo#3591

 - Also fixes the save form fails select other object issue
  • Loading branch information
maurofmferrao authored Feb 17, 2025
1 parent f344c01 commit 21f0b9e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
40 changes: 27 additions & 13 deletions ui/src/core/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -3187,13 +3187,17 @@ window.forms = {
* @param {*} baseObject - The base object to replace
*/
handleFormReplacements: function(container, baseObject) {
const regExpMatchBetweenPercent = /%([^%\s]+)%/g;

const replaceHTML = function(htmlString) {
htmlString = htmlString.replace(/\%(.*?)\%/g, function(_m, group) {
// Replace trimmed match with the value of the base object
return group.split('.').reduce((a, b) => {
return (a[b]) || `%${b}%`;
}, baseObject);
});
htmlString = htmlString.replace(
regExpMatchBetweenPercent,
function(_m, group) {
// Replace trimmed match with the value of the base object
return group.split('.').reduce((a, b) => {
return (a[b]) || `%${b}%`;
}, baseObject);
});

return htmlString;
};
Expand All @@ -3206,8 +3210,11 @@ window.forms = {
const elementAlternativeTitle = $element.attr('data-original-title');

// If theres title and it contains a replacement special character
if (elementTitle && elementTitle.indexOf('%') > -1) {
$element.attr('title', replaceHTML(elementTitle));
if (elementTitle) {
const matches = elementTitle.match(regExpMatchBetweenPercent);
if (matches) {
$element.attr('title', replaceHTML(elementTitle));
}
}

// If theres an aletrnative title and it
Expand All @@ -3216,9 +3223,13 @@ window.forms = {
elementAlternativeTitle &&
elementAlternativeTitle.indexOf('%') > -1
) {
$element.attr(
'data-original-title',
replaceHTML(elementAlternativeTitle));
const matches = elementAlternativeTitle
.match(regExpMatchBetweenPercent);
if (matches) {
$element.attr(
'data-original-title',
replaceHTML(elementAlternativeTitle));
}
}
});

Expand All @@ -3229,8 +3240,11 @@ window.forms = {
const elementInnerHTML = $element.html();

// If theres inner html and it contains a replacement special character
if (elementInnerHTML && elementInnerHTML.indexOf('%') > -1) {
$element.html(replaceHTML(elementInnerHTML));
if (elementInnerHTML) {
const matches = elementInnerHTML.match(regExpMatchBetweenPercent);
if (matches) {
$element.html(replaceHTML(elementInnerHTML));
}
}
});
},
Expand Down
6 changes: 6 additions & 0 deletions ui/src/editor-core/properties-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ PropertiesPanel.prototype.save = function(
const errorMessage = Object.values(errors).join('</br>');
// Display message in form
formHelpers.displayErrorMessage(form, errorMessage, 'danger');

// Call callback without waiting for the request
(callbackNoWait) && callbackNoWait();

// Mark form as not needed to be saved anymore
this.toSave = false;
return false;
} else {
formHelpers.clearErrorMessage(form);
Expand Down

0 comments on commit 21f0b9e

Please sign in to comment.