Skip to content

Commit 590591f

Browse files
mayankjindalmjfarha-haroon-adobeMayank Jindalclaude
authored
FORMS-26813 : Show custom acceptMessage for unsupported file type in File Attachment (#1943)
* Fix custom accept error message not shown for unsupported file type in file input The file-input widget's invalidMessage() looked up constraintMessages.invalidMimeType for the unsupported-file-type alert, but invalidMimeType is not an authorable constraint message key - the schema only exposes constraintMessages.accept (backed by the acceptMessage dialog property). As a result the custom message authors configure for file type validation was always ignored in favor of the generic fallback string, while the analogous maxFileSize custom message worked correctly since its key matched. Updated both the webpack source (ui.frontend) and the apps clientlib copy (ui.af.apps) to read constraintMessages.accept, and added a Cypress assertion mirroring the existing maxFileSize custom-message test. * FORMS-26813 : populate sample.afe fixture so the unsupported-type test reaches the mime-type (accept) check instead of the empty-file check Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * FORMS-26813 : use existing sample.svg fixture on fileinput3 for the unsupported-type test Point the accept test at fileinput3 (accept=[application/pdf]) and upload sample.svg (an image, unsupported there) instead of populating a sample.afe placeholder. svg is non-empty so it passes the empty-file check and reaches the mime-type (accept) check. Matches the release/650 backport (#1940). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Farha Haroon <fharoon@adobe.com> Co-authored-by: Mayank Jindal <mayankjindal@adobe.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 040f877 commit 590591f

4 files changed

Lines changed: 13 additions & 2 deletions

File tree

it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/fileinput/fileinputv4/basic/.content.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
jcr:title="File Input - 3"
5454
sling:resourceType="core/fd/components/form/fileinput/v4/fileinput"
5555
accept="[application/pdf]"
56+
acceptMessage="This file type is not supported!"
5657
description="This is long description"
5758
fieldType="file-input"
5859
id="fileinput_tooltip_scenario_test"

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/fileinput/v4/fileinput/clientlibs/site/js/fileinputwidget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ if (typeof window.FileInputWidget === 'undefined') {
191191
const messages = {
192192
[this.invalidFeature.SIZE]: customMessages.maxFileSize || FormView.LanguageUtils.getTranslatedString(this.lang, "FileSizeGreater", [fileNames, this.options.maxFileSize]),
193193
[this.invalidFeature.NAME]: customMessages.invalidFileName || FormView.LanguageUtils.getTranslatedString(this.lang, "FileNameInvalid", [fileNames]),
194-
[this.invalidFeature.MIMETYPE]: customMessages.invalidMimeType || FormView.LanguageUtils.getTranslatedString(this.lang, "FileMimeTypeInvalid", [fileNames]),
194+
[this.invalidFeature.MIMETYPE]: customMessages.accept || FormView.LanguageUtils.getTranslatedString(this.lang, "FileMimeTypeInvalid", [fileNames]),
195195
[this.invalidFeature.SIZE_ZERO]: customMessages.zeroFileSize || FormView.LanguageUtils.getTranslatedString(this.lang, "FileSizeZero", [fileNames])
196196
};
197197
return messages[invalidFeature];

ui.frontend/src/view/FormFileInputWidgetBase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class FormFileInputWidgetBase {
340340
const messages = {
341341
[this.invalidFeature.SIZE]: customMessages.maxFileSize || FormView.LanguageUtils.getTranslatedString(this.lang, "FileSizeGreater", [fileName, this.options.maxFileSize]),
342342
[this.invalidFeature.NAME]: customMessages.invalidFileName || FormView.LanguageUtils.getTranslatedString(this.lang, "FileNameInvalid", [fileName]),
343-
[this.invalidFeature.MIMETYPE]: customMessages.invalidMimeType || FormView.LanguageUtils.getTranslatedString(this.lang, "FileMimeTypeInvalid", [fileName])
343+
[this.invalidFeature.MIMETYPE]: customMessages.accept || FormView.LanguageUtils.getTranslatedString(this.lang, "FileMimeTypeInvalid", [fileName])
344344
};
345345

346346
alert(messages[invalidFeature]);

ui.tests/test-module/specs/fileinput/fileinputv4.runtime.cy.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ describe('Click on button tag (V-4)', () => {
272272
});
273273
});
274274

275+
it('should display a custom error message configured by the user for unsupported file type', () => {
276+
const [id, fieldView] = Object.entries(formContainer._fields)[2];
277+
const model = formContainer._model.getElement(id);
278+
const fileInput = "input[name='fileinput3']";
279+
cy.attachFile(fileInput, ['sample.svg']);
280+
cy.on('window:alert', (alertText) => {
281+
expect(alertText).to.equal(model.getState().constraintMessages.accept);
282+
});
283+
});
284+
275285
it('file when uploaded again should give actual size', () => {
276286
let sampleFileNames = ['sample.svg'];
277287
const fileInput = "input[name='fileinput2']";

0 commit comments

Comments
 (0)