-
Notifications
You must be signed in to change notification settings - Fork 58
Forms 18927 allow extensions support in file input #1586
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
base: dev
Are you sure you want to change the base?
Changes from all commits
6090023
f318496
1e4b082
f67107d
8df457a
3263fc7
38f946d
b0dfd43
7e2935a
225daa2
691b641
396b6cb
58e07d3
e525b83
49cd2ed
cd411cd
c10b1e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" | ||
jcr:primaryType="sling:Folder"/> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" | ||
jcr:primaryType="cq:ClientLibraryFolder" | ||
categories="[core.forms.components.fileinput.v3.editor]" | ||
jsProcessor="[default:none,min:gcc;languageIn=ECMASCRIPT_2021;languageOut=ECMASCRIPT_2021]" | ||
dependencies="[core.forms.components.base.v1.editor, core.forms.components.commons.v1.editor.utils]"/> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
############################################################################### | ||
# Copyright 2025 Adobe | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
############################################################################### | ||
|
||
#base=js | ||
editDialog.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/******************************************************************************* | ||
* Copyright 2025 Adobe | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
******************************************************************************/ | ||
(function($) { | ||
"use strict"; | ||
let EDIT_DIALOG = ".cmp-adaptiveform-fileinput__editdialog", | ||
FILEINPUT_MIMETYPE = EDIT_DIALOG + " .cmp-adaptiveform-fileinput__mimeType", | ||
FILEINPUT_EXTENSIONS = EDIT_DIALOG + " .cmp-adaptiveform-fileinput__extensions", | ||
Utils = window.CQ.FormsCoreComponents.Utils.v1; | ||
|
||
function handleMimeType(dialog) { | ||
let mimeTypeWrapper = dialog.find(FILEINPUT_MIMETYPE); | ||
let mimeTypeField = mimeTypeWrapper.find("coral-multifield"); | ||
let extensionsField = dialog.find(FILEINPUT_EXTENSIONS + " coral-multifield"); | ||
let mimeTypeFieldInfoIcon = mimeTypeWrapper.find('coral-icon.coral-Form-fieldinfo'); | ||
|
||
function updateMimeTypeState() { | ||
let hasExtensions = extensionsField.find('coral-multifield-item').length > 0; | ||
|
||
// Disable the entire multifield and its contents | ||
mimeTypeField.css({ | ||
'pointer-events': hasExtensions ? 'none' : 'auto', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pls manage css by adding relevant classes rather inside the js itself. |
||
'opacity': hasExtensions ? '0.5' : '1' | ||
}); | ||
mimeTypeField.prop('disabled', hasExtensions); | ||
|
||
// Disable delete icons and their SVGs | ||
mimeTypeField.find('coral-icon[icon="delete"], ._coral-Icon--svg').css({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anything that starts with a underscore is an internal coral selector. We should not use any coral internals in the code. |
||
'pointer-events': hasExtensions ? 'none' : 'auto' | ||
}); | ||
|
||
// Handle MIME type items if extensions exist | ||
if (hasExtensions) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not immediately clear from this code that what, why and when do we intend to do this |
||
// Keep first item, remove others | ||
let firstItem = mimeTypeField.find('coral-multifield-item').first(); | ||
|
||
// If no first item exists, create one | ||
if (firstItem.length === 0) { | ||
// Click the add button to create a new item | ||
mimeTypeField.find('button[coral-multifield-add]').click(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than simulating clicks we should be using add API for Multi field. |
||
firstItem = mimeTypeField.find('coral-multifield-item').first(); | ||
} | ||
|
||
mimeTypeField.find('coral-multifield-item:not(:first)').remove(); | ||
|
||
// Set value of first item to */* | ||
firstItem.find('input').val('*/*'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this "firstItem.find('input').val('/');" means all mimetypes are allowed or ignored? |
||
} | ||
|
||
if(mimeTypeFieldInfoIcon.length > 0) { | ||
// show the info icon | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Info icon should be present by default, not based on condition There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rajatofficial To confirm - this is need because it is behind FT? |
||
mimeTypeFieldInfoIcon.css({ | ||
'display': hasExtensions ? '' : 'none' | ||
}); | ||
} | ||
} | ||
|
||
// Watch for changes in both fields | ||
extensionsField.on('change', updateMimeTypeState); | ||
mimeTypeField.on('change', updateMimeTypeState); | ||
|
||
// Check initial state without triggering events | ||
let hasExtensions = extensionsField.find('coral-multifield-item').length > 0; | ||
if (hasExtensions) { | ||
mimeTypeField.css({ | ||
'pointer-events': 'none', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Html5 file accept allows mimetypes and extensions to be set simultaneously. is there any specific reason for this otherwise behavior in our component? |
||
'opacity': '0.5' | ||
}); | ||
mimeTypeField.prop('disabled', true); | ||
mimeTypeField.find('coral-icon[icon="delete"], ._coral-Icon--svg').css({ | ||
'pointer-events': 'none' | ||
}); | ||
} | ||
} | ||
|
||
$(document).on('dialog-loaded', EDIT_DIALOG, function(e) { | ||
handleMimeType($(this)); | ||
}); | ||
|
||
Utils.initializeEditDialog(EDIT_DIALOG)(handleMimeType); | ||
|
||
})(jQuery); |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any new prop persisted in jcr should being with
fd: