Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stock Symbols: input not working for single element #2915

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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