Skip to content

Commit

Permalink
Merge pull request #138 from formio/FIO-8848-Error-message-appears-wh…
Browse files Browse the repository at this point in the history
…en-attempting-to-add-Select-with-Raw-JSON-Data-Source-Type

FIO-8848 fixed validation for TextArea with Save as Json
  • Loading branch information
brendanbond authored Aug 21, 2024
2 parents 6c3ff4d + 28a6faa commit d596125
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/process/validation/rules/__tests__/validateMultiple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('validateMultiple', () => {
expect(isEligible(component)).to.be.true;
});

it('should return false for textArea component with as !== json', () => {
it('should return false for textArea component with as !== json if multiple', () => {
const component: TextAreaComponent = {
type: 'textarea',
as: 'text',
Expand All @@ -50,9 +50,9 @@ describe('validateMultiple', () => {
expect(isEligible(component)).to.be.false;
});

it('should return true for textArea component with as === json', () => {
it('should return true for textArea component with as === json if multiple', () => {
const component: TextAreaComponent = {
type: 'textArea',
type: 'textarea',
as: 'json',
input: true,
key: 'textAreaJson',
Expand All @@ -66,6 +66,21 @@ describe('validateMultiple', () => {
expect(isEligible(component)).to.be.true;
});

it('should return false for textArea component with as === json if not multiple', () => {
const component: TextAreaComponent = {
type: 'textarea',
as: 'json',
input: true,
key: 'textAreaJson',
rows: 4,
wysiwyg: true,
editor: 'ace',
fixedSize: true,
inputFormat: 'plain',
};
expect(isEligible(component)).to.be.false;
});

it('should return true for other component types', () => {
const component: Component = {
type: 'textfield',
Expand Down
3 changes: 2 additions & 1 deletion src/process/validation/rules/validateMultiple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const isEligible = (component: Component) => {
case 'textarea':
if (
!(component as TextAreaComponent).as ||
(component as TextAreaComponent).as !== 'json'
(component as TextAreaComponent).as !== 'json' ||
((component as TextAreaComponent).as === 'json' && !component.multiple)
) {
return false;
}
Expand Down

0 comments on commit d596125

Please sign in to comment.