Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond committed Nov 1, 2024
2 parents b490f6e + 51dd947 commit c36864a
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 31 deletions.
91 changes: 91 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4402,6 +4402,97 @@ describe('Process Tests', function () {
});
});

it('Should not return errors for empty multiple values for url and dateTime', function () {
const form = {
_id: '671f7fbeaf87b0e2a26e4212',
title: 'form2',
name: 'form2',
path: 'form2',
type: 'form',
display: 'form',
components: [
{
label: 'Url',
applyMaskOn: 'change',
tableView: true,
multiple: true,
validateWhenHidden: false,
key: 'url',
type: 'url',
input: true,
},
{
label: 'Date / Time',
tableView: false,
datePicker: {
disableWeekends: false,
disableWeekdays: false,
},
multiple: true,
enableMinDateInput: false,
enableMaxDateInput: false,
validateWhenHidden: false,
key: 'dateTime',
type: 'datetime',
input: true,
widget: {
type: 'calendar',
displayInTimezone: 'viewer',
locale: 'en',
useLocaleSettings: false,
allowInput: true,
mode: 'single',
enableTime: true,
noCalendar: false,
format: 'yyyy-MM-dd hh:mm a',
hourIncrement: 1,
minuteIncrement: 1,
time_24hr: false,
minDate: null,
disableWeekends: false,
disableWeekdays: false,
maxDate: null,
},
},
{
type: 'button',
label: 'Submit',
key: 'submit',
disableOnInvalid: true,
input: true,
tableView: false,
},
],
created: '2024-10-28T12:12:46.715Z',
modified: '2024-10-29T10:18:00.534Z',
};

const submission = {
data: { url: [], dateTime: [], submit: true },
state: 'submitted',
};

const errors: any = [];
const conditionals: any = [];
const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.submission,
scope: { errors, conditionals },
config: {
server: true,
},
};

processSync(context);
submission.data = context.data;
context.processors = ProcessTargets.evaluator;
processSync(context);
assert.deepEqual(context.scope.errors.length, 0);
});

describe('Required component validation in nested form in DataGrid/EditGrid', function () {
const nestedForm = {
key: 'form',
Expand Down
6 changes: 3 additions & 3 deletions src/process/conditions/__tests__/conditions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ describe('Condition processor', function () {
{
component: 'selectBoxes',
operator: 'isNotEqual',
value: '3'
}
]
value: '3',
},
],
},
type: 'textfield',
input: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,12 @@ describe('validateAvailableItems', function () {
context.fetch = () => {
return Promise.resolve({
ok: true,
json: () => Promise.resolve([
{ label: '1', value: '1' },
{ label: '2', value: '2' },
{ label: '3', value: '3' },
]),
json: () =>
Promise.resolve([
{ label: '1', value: '1' },
{ label: '2', value: '2' },
{ label: '3', value: '3' },
]),
});
};
const result = await validateAvailableItems(context);
Expand All @@ -505,11 +506,12 @@ describe('validateAvailableItems', function () {
context.fetch = () => {
return Promise.resolve({
ok: true,
json: () => Promise.resolve([
{ label: '1', value: '1' },
{ label: '2', value: '2' },
{ label: '3', value: '3' },
]),
json: () =>
Promise.resolve([
{ label: '1', value: '1' },
{ label: '2', value: '2' },
{ label: '3', value: '3' },
]),
});
};
const result = await validateAvailableItems(context);
Expand Down
5 changes: 3 additions & 2 deletions src/process/validation/rules/validateAvailableItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ export const validateAvailableItems: RuleFn = async (context: ValidationContext)
? null
: error;
}
return values.find((optionValue) => optionValue.value === value || optionValue === value) !==
undefined
return values.find(
(optionValue) => optionValue.value === value || optionValue === value,
) !== undefined
? null
: error;
}
Expand Down
5 changes: 5 additions & 0 deletions src/process/validation/rules/validateDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export const shouldValidate = (context: ValidationContext) => {
if (!value || !isValidatable(component)) {
return false;
}

if (component.multiple && Array.isArray(value) && value.length === 0) {
return false;
}

return true;
};

Expand Down
5 changes: 5 additions & 0 deletions src/process/validation/rules/validateUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const shouldValidate = (context: ValidationContext) => {
if (!isUrlComponent(component)) {
return false;
}

if (component.multiple && Array.isArray(value) && value.length === 0) {
return false;
}

if (!value) {
return false;
}
Expand Down
25 changes: 15 additions & 10 deletions src/sdk/Formio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2370,17 +2370,23 @@ export class Formio {
* @param {HTMLElement} rootElement - The element after which the resource would be attached (useful when requiring resources from ShadowRoot).
* @return {Promise<object>} - A promise that will resolve when the plugin is ready to be used.
*/
static requireLibrary(name: string, property: string, src: string | Array<string>, polling: boolean = false, onload?: (ready: Promise<any>) => void, rootElement?: HTMLElement ) {

static requireLibrary(
name: string,
property: string,
src: string | Array<string>,
polling: boolean = false,
onload?: (ready: Promise<any>) => void,
rootElement?: HTMLElement,
) {
const resourceToDomOptions = {
name,
src,
formio:Formio,
formio: Formio,
onload,
rootElement
}
rootElement,
};

let hasResourceBeenAdded = false
let hasResourceBeenAdded = false;

if (!Formio.libraries.hasOwnProperty(name)) {
Formio.libraries[name] = {};
Expand All @@ -2399,9 +2405,8 @@ export class Formio {
const plugin = get(window, property);
if (plugin) {
Formio.libraries[name].resolve(plugin);
}
else {
attachResourceToDom(resourceToDomOptions)
} else {
attachResourceToDom(resourceToDomOptions);
hasResourceBeenAdded = true;

// if no callback is provided, then check periodically for the script.
Expand All @@ -2419,7 +2424,7 @@ export class Formio {

const lib = Formio.libraries[name];

if(rootElement && !hasResourceBeenAdded) {
if (rootElement && !hasResourceBeenAdded) {
attachResourceToDom(resourceToDomOptions);
}

Expand Down
12 changes: 6 additions & 6 deletions src/types/ResourceToDomOptions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Formio } from "sdk";
import { Formio } from 'sdk';

export type ResourceToDomOptions = {
name: string,
src: string | Array<string>,
formio: typeof Formio,
onload?: (ready: Promise<any>) => void,
rootElement?: HTMLElement
name: string;
src: string | Array<string>;
formio: typeof Formio;
onload?: (ready: Promise<any>) => void;
rootElement?: HTMLElement;
};

0 comments on commit c36864a

Please sign in to comment.