Skip to content

Commit 227475f

Browse files
authored
feat(input_schema): Add textfield editor support to resource property (#557)
This adds support for: - `textfield` editor - and validation keywords (`pattern`, `minLength`, `maxLength`) for resource properties (fields with `resourceType`). Based on the outcome of discussion here: https://apify.slack.com/archives/C081VA3BSCR/p1761036999960109?thread_ts=1760009084.798619&cid=C081VA3BSCR In the UI this would work out of the box with default editor of `resourcePicker`.
1 parent 1621e04 commit 227475f

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

packages/json_schemas/schemas/input.schema.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@
500500
"type": { "enum": ["string"] },
501501
"title": { "type": "string" },
502502
"description": { "type": "string" },
503-
"editor": { "enum": ["resourcePicker", "hidden"] },
503+
"editor": { "enum": ["resourcePicker", "textfield", "hidden"] },
504504
"resourceType": { "enum": ["dataset", "keyValueStore", "requestQueue"] },
505505
"resourcePermissions": {
506506
"type": "array",
@@ -517,6 +517,9 @@
517517
"prefill": { "type": "string" },
518518
"example": { "type": "string" },
519519
"nullable": { "type": "boolean" },
520+
"pattern": { "type": "string" },
521+
"minLength": { "type": "integer" },
522+
"maxLength": { "type": "integer" },
520523
"sectionCaption": { "type": "string" },
521524
"sectionDescription": { "type": "string" }
522525
},
@@ -951,7 +954,7 @@
951954
"type": { "enum": ["string"] },
952955
"title": { "type": "string" },
953956
"description": { "type": "string" },
954-
"editor": { "enum": ["resourcePicker", "hidden"] },
957+
"editor": { "enum": ["resourcePicker", "textfield", "hidden"] },
955958
"resourceType": { "enum": ["dataset", "keyValueStore", "requestQueue"] },
956959
"resourcePermissions": {
957960
"type": "array",
@@ -967,7 +970,10 @@
967970
},
968971
"prefill": { "type": "string" },
969972
"example": { "type": "string" },
970-
"nullable": { "type": "boolean" }
973+
"nullable": { "type": "boolean" },
974+
"pattern": { "type": "string" },
975+
"minLength": { "type": "integer" },
976+
"maxLength": { "type": "integer" }
971977
},
972978
"required": ["type", "title", "description", "resourceType"],
973979
"if": {

test/input_schema.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,27 @@ describe('input_schema.json', () => {
349349
);
350350
});
351351

352+
it('should accept valid editor', () => {
353+
const validEditors = ['resourcePicker', 'textfield', 'hidden'];
354+
validEditors.forEach((editor) => {
355+
const schema = {
356+
title: 'Test input schema',
357+
type: 'object',
358+
schemaVersion: 1,
359+
properties: {
360+
myField: {
361+
title: 'Field title',
362+
description: 'My test field',
363+
type: 'string',
364+
resourceType: 'keyValueStore',
365+
editor,
366+
},
367+
},
368+
};
369+
expect(() => validateInputSchema(validator, schema)).not.toThrow();
370+
});
371+
});
372+
352373
it('should not accept invalid editor', () => {
353374
const schema = {
354375
title: 'Test input schema',
@@ -360,12 +381,13 @@ describe('input_schema.json', () => {
360381
description: 'My test field',
361382
type: 'string',
362383
resourceType: 'keyValueStore',
363-
editor: 'textfield',
384+
editor: 'textarea',
364385
},
365386
},
366387
};
367388
expect(() => validateInputSchema(validator, schema)).toThrow(
368-
'Input schema is not valid (Field schema.properties.myField.editor must be equal to one of the allowed values: "resourcePicker", "hidden")',
389+
// eslint-disable-next-line max-len
390+
'Input schema is not valid (Field schema.properties.myField.editor must be equal to one of the allowed values: "resourcePicker", "textfield", "hidden")',
369391
);
370392
});
371393

0 commit comments

Comments
 (0)