Skip to content

Commit

Permalink
feat(templates): add validation to textarea and select
Browse files Browse the repository at this point in the history
  • Loading branch information
smbea committed Jan 25, 2024
1 parent ce81139 commit 2db1396
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 96 deletions.
12 changes: 8 additions & 4 deletions src/element-templates/properties/CustomProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ function DropdownProperty(props) {
} = property;

const bpmnFactory = useService('bpmnFactory'),
commandStack = useService('commandStack');
commandStack = useService('commandStack'),
translate = useService('translate');

const getOptions = () => {
const { choices } = property;
Expand All @@ -316,7 +317,8 @@ function DropdownProperty(props) {
description: PropertyDescription({ description }),
getValue: propertyGetter(element, property, scope),
setValue: propertySetter(bpmnFactory, commandStack, element, property, scope),
disabled: editable === false
disabled: editable === false,
validate: propertyValidator(translate, property)
});
}

Expand Down Expand Up @@ -368,7 +370,8 @@ function TextAreaProperty(props) {

const bpmnFactory = useService('bpmnFactory'),
commandStack = useService('commandStack'),
debounce = useService('debounceInput');
debounce = useService('debounceInput'),
translate = useService('translate');

return TextAreaEntry({
debounce,
Expand All @@ -378,7 +381,8 @@ function TextAreaProperty(props) {
description: PropertyDescription({ description }),
getValue: propertyGetter(element, property, scope),
setValue: propertySetter(bpmnFactory, commandStack, element, property, scope),
disabled: editable === false
disabled: editable === false,
validate: propertyValidator(translate, property)
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</bpmn:sequenceFlow>
<bpmn:serviceTask id="DelegateTask" name="Delegate Task" camunda:modelerTemplate="my.custom.ServiceTask" camunda:delegateExpression="com.my.custom.Foo" />
<bpmn:task id="WebserviceTask_NoData" name="Webservice Task NoData" camunda:modelerTemplate="com.mycompany.WsCaller" />
<bpmn:task id="ValidateTask" name="Validate Task" camunda:modelerTemplate="com.validated-inputs.Task" />
<bpmn:task id="ValidateTask" camunda:modelerTemplate="com.validated-inputs.Task" />
<bpmn:callActivity id="CallActivity" name="Call Activity" camunda:modelerTemplate="my.Caller" calledElement="calledProcess">
<bpmn:extensionElements>
<camunda:in source="var_local" target="var_called_source" />
Expand Down
242 changes: 224 additions & 18 deletions test/spec/element-templates/properties/CustomProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,62 +313,81 @@
"appliesTo": [
"bpmn:Task"
],
"groups": [
{
"id": "input",
"label": "Textfield"
},
{
"id": "textarea",
"label": "Textarea"
},
{
"id": "select",
"label": "Select"
}
],
"properties": [
{
"label": "NotEmpty",
"label": "String - NotEmpty",
"description": "Must not be empty",
"type": "String",
"group": "input",
"binding": {
"type": "camunda:property",
"name": "prop"
"type": "property",
"name": "name"
},
"constraints": {
"notEmpty": true
}
},
{
"label": "MinLength",
"label": "String - MinLength",
"description": "Must have min length 5",
"type": "String",
"group": "input",
"binding": {
"type": "camunda:property",
"name": "prop"
"type": "property",
"name": "name"
},
"constraints": {
"minLength": 5
}
},
{
"label": "MaxLength",
"label": "String - MaxLength",
"description": "Must have max length 5",
"type": "String",
"group": "input",
"binding": {
"type": "camunda:property",
"name": "prop"
"type": "property",
"name": "name"
},
"constraints": {
"maxLength": 5
}
},
{
"label": "Pattern (String)",
"label": "String - Pattern (String)",
"description": "Must match /A+B/",
"type": "String",
"group": "input",
"binding": {
"type": "camunda:property",
"name": "prop"
"type": "property",
"name": "name"
},
"constraints": {
"pattern": "A+B"
}
},
{
"label": "Pattern (String + Message)",
"label": "String - Pattern (String + Message)",
"description": "Must be https url",
"type": "String",
"group": "input",
"binding": {
"type": "camunda:property",
"name": "prop"
"type": "property",
"name": "name"
},
"constraints": {
"pattern": {
Expand All @@ -378,19 +397,206 @@
}
},
{
"label": "Pattern (Integer)",
"label": "String - Pattern (Integer)",
"description": "Must be integer",
"type": "String",
"group": "input",
"binding": {
"type": "camunda:property",
"name": "prop"
"type": "property",
"name": "name"
},
"constraints": {
"pattern": {
"message": "Must be positive integer",
"value": "\\d+"
}
}
},
{
"label": "TextArea - NotEmpty",
"description": "Must not be empty",
"type": "Text",
"group": "textarea",
"binding": {
"type": "property",
"name": "name"
},
"constraints": {
"notEmpty": true
}
},
{
"label": "TextArea - MinLength",
"description": "Must have min length 5",
"type": "Text",
"group": "textarea",
"binding": {
"type": "property",
"name": "name"
},
"constraints": {
"minLength": 5
}
},
{
"label": "TextArea - MaxLength",
"description": "Must have max length 5",
"type": "Text",
"group": "textarea",
"binding": {
"type": "property",
"name": "name"
},
"constraints": {
"maxLength": 5
}
},
{
"label": "TextArea - Pattern (String)",
"description": "Must match /A+B/",
"type": "Text",
"group": "textarea",
"binding": {
"type": "property",
"name": "name"
},
"constraints": {
"pattern": "A+B"
}
},
{
"label": "TextArea - Pattern (String + Message)",
"description": "Must be https url",
"type": "Text",
"group": "textarea",
"binding": {
"type": "property",
"name": "name"
},
"constraints": {
"pattern": {
"message": "Must start with https://",
"value": "https://.*"
}
}
},
{
"label": "TextArea - Pattern (Integer)",
"description": "Must be integer",
"type": "Text",
"group": "textarea",
"binding": {
"type": "property",
"name": "name"
},
"constraints": {
"pattern": {
"message": "Must be positive integer",
"value": "\\d+"
}
}
},
{
"label": "Select - NotEmpty",
"description": "Must not be empty",
"type": "Dropdown",
"choices": [
{ "name": "FOOO", "value": "FOO" }
],
"group": "select",
"binding": {
"type": "property",
"name": "name"
},
"constraints": {
"notEmpty": true
}
},
{
"label": "Select - MinLength",
"description": "Must have min length 5",
"type": "Dropdown",
"group": "select",
"binding": {
"type": "property",
"name": "name"
},
"choices": [
{ "name": "FOOOOOOO", "value": "FOOOOOOO" }
],
"constraints": {
"minLength": 5
}
},
{
"label": "Select - MaxLength",
"description": "Must have max length 5",
"type": "Dropdown",
"group": "select",
"binding": {
"type": "property",
"name": "name"
},
"choices": [
{ "name": "FOOOOOOO", "value": "FOOOOOOO" }
],
"constraints": {
"maxLength": 5
}
},
{
"label": "Select - Pattern (String)",
"description": "Must match /A+B/",
"type": "Dropdown",
"group": "select",
"choices": [
{ "name": "AAAB", "value": "AAAB" }
],
"binding": {
"type": "property",
"name": "name"
},
"constraints": {
"pattern": "A+B"
}
},
{
"label": "Select - Pattern (String + Message)",
"description": "Must be https url",
"type": "Dropdown",
"group": "select",
"choices": [
{ "name": "https://", "value": "https://" }
],
"binding": {
"type": "property",
"name": "name"
},
"constraints": {
"pattern": {
"message": "Must start with https://",
"value": "https://.*"
}
}
},
{
"label": "Select - Pattern (Integer)",
"description": "Must be integer",
"type": "Dropdown",
"group": "select",
"binding": {
"type": "property",
"name": "name"
},
"choices": [
{ "name": "20", "value": "20" }
],
"constraints": {
"pattern": {
"message": "Must be positive integer",
"value": "\\d+"
}
}
}
]
},
Expand Down
Loading

0 comments on commit 2db1396

Please sign in to comment.