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

added readOnly in formTemplate #1280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions webplugin/js/app/km-richtext-markup-1.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ Kommunicate.markup = {
</div>
</div>`;
},
getImageTemplate: function () {
getImageTemplate: function () {
return `<div>
{{#payload}}
<div class="km-image-template">
Expand Down Expand Up @@ -500,7 +500,7 @@ Kommunicate.markup = {
{{/validation}}
<label for="{{label}}" class="mck-form-label"><b>{{label}}</b></label>
</div>
<input type="{{type}}" placeholder="{{placeholder}}" name="{{label}}" data-regex="{{validation.regex}}" data-error-text="{{validation.errorText}}">
<input type="{{type}}" placeholder="{{placeholder}}" name="{{label}}" data-regex="{{validation.regex}}" {{#readonly}}readonly{{/readonly}} data-error-text="{{validation.errorText}}">
{{#validation}}
<div class="mck-form-error-container mck-form-{{className}}-error-container n-vis">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 12 12" fill="none">
Expand Down Expand Up @@ -906,8 +906,10 @@ Kommunicate.markup.getImageContainer = function (options) {
typeof options.payload == 'string'
? JSON.parse(options.payload)
: {};
options.payload = JSON.parse(JSON.stringify(payload))
options.payload?.forEach((payload) => { payload.type = payload.url?.split(".").pop()?.toLowerCase()});
options.payload = JSON.parse(JSON.stringify(payload));
options.payload?.forEach((payload) => {
payload.type = payload.url?.split('.').pop()?.toLowerCase();
});
Comment on lines +909 to +912
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Browser compatibility issue confirmed - Optional chaining not supported in IE

The codebase explicitly checks for Internet Explorer compatibility in mck-app.js and contains browser detection code. Since there's no transpilation setup and IE support is required, the use of optional chaining (?.) should be replaced with the suggested compatible approach:

options.payload && options.payload.forEach((payload) => {
    payload.type = payload.url && payload.url.split('.').pop() && payload.url.split('.').pop().toLowerCase();
});
🔗 Analysis chain

Consider browser compatibility for optional chaining.

While the logic for extracting file extensions is good, the use of optional chaining (?.) and nullish coalescing operators (??) might not be supported in older browsers, particularly Internet Explorer which was mentioned in the PR description.

Run this script to check browser compatibility requirements:

Consider using a more compatible approach:

-        options.payload?.forEach((payload) => {
-            payload.type = payload.url?.split('.').pop()?.toLowerCase();
+        options.payload && options.payload.forEach((payload) => {
+            payload.type = payload.url && payload.url.split('.').pop() && payload.url.split('.').pop().toLowerCase();
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for browser compatibility requirements in package.json or similar files
# Look for babel config or browserslist config that might indicate target browsers

# Search for package.json
echo "Checking package.json for browser targets..."
fd "package.json" --exec cat {} \; | jq -r '.browserslist // .babel // empty'

# Search for .browserslistrc
echo "Checking .browserslistrc..."
fd ".browserslistrc" --exec cat {} \;

# Search for babel.config.js
echo "Checking babel.config.js..."
fd "babel.config.js" --exec cat {} \;

Length of output: 391


Script:

#!/bin/bash
# Check for webpack configs and other build tool configurations
echo "Checking for webpack and other build configs..."
fd -e config.js -e webpack.config.js

# Look for IE-specific comments or patterns in JS files
echo -e "\nChecking for IE-related patterns in JS files..."
rg -i "internet explorer|msie|trident" --type js

# Check for polyfills
echo -e "\nChecking for polyfills..."
rg -i "polyfill|babel|core-js" --type js

Length of output: 87157

return Mustache.to_html(Kommunicate.markup.getImageTemplate(), options);
}
return '';
Expand Down Expand Up @@ -984,6 +986,11 @@ Kommunicate.markup.getActionableFormMarkup = function (options) {
item.type
) != -1;
options.payload[index][item.type] = true;

if (item.readonly) {
options.payload[index].readonly = true; // Add readonly to the payload
}

try {
options.payload[index].className = (item.label || item.name)
.toLowerCase()
Expand Down
Loading