Skip to content

Commit

Permalink
feat: allow select & multiple select to have custom input options wit…
Browse files Browse the repository at this point in the history
…h new property `allowInput`

close #4696
  • Loading branch information
Skraye committed Sep 10, 2024
1 parent af4fc14 commit b321962
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.kestra.core.validations.Regex;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -38,6 +39,14 @@ public class MultiselectInput extends Input<List<String>> implements ItemTypeInt
@Builder.Default
private Type itemType = Type.STRING;


@Schema(
title = "If the user can provide customs value."
)
@NotNull
@Builder.Default
Boolean allowInput = false;

@Override
public void validate(List<String> inputs) throws ConstraintViolationException {
if (values != null && options != null) {
Expand All @@ -50,16 +59,18 @@ public void validate(List<String> inputs) throws ConstraintViolationException {
);
}

for(String input : inputs){
List<@Regex String> finalValues = this.values != null ? this.values : this.options;
if (!finalValues.contains(input)) {
throw ManualConstraintViolation.toConstraintViolationException(
"it must match the values `" + finalValues + "`",
this,
MultiselectInput.class,
getId(),
input
);
if (!this.getAllowInput()) {
for (String input : inputs) {
List<@Regex String> finalValues = this.values != null ? this.values : this.options;
if (!finalValues.contains(input)) {
throw ManualConstraintViolation.toConstraintViolationException(
"it must match the values `" + finalValues + "`",
this,
MultiselectInput.class,
getId(),
input
);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
Expand All @@ -22,9 +23,20 @@ public class SelectInput extends Input<String> {
@NotNull
List<@Regex String> values;

@Schema(
title = "If the user can provide a custom value."
)
@NotNull
@Builder.Default
Boolean allowInput = false;


@Override
public void validate(String input) throws ConstraintViolationException {
if (!values.contains(input) & this.getRequired()) {
if (this.getAllowInput()) {
return;
}
throw ManualConstraintViolation.toConstraintViolationException(
"it must match the values `" + values + "`",
this,
Expand Down
4 changes: 4 additions & 0 deletions ui/src/components/inputs/InputsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
v-if="input.type === 'ENUM' || input.type === 'SELECT'"
v-model="inputs[input.id]"
@update:model-value="onChange"
:allow-create="input.allowInput"
filterable
>
<el-option
v-for="item in input.values"
Expand All @@ -40,6 +42,8 @@
v-model="multiSelectInputs[input.id]"
@update:model-value="onMultiSelectChange(input.id, $event)"
multiple
filterable
:allow-create="input.allowInput"
>
<el-option
v-for="item in (input.values ?? input.options)"
Expand Down

0 comments on commit b321962

Please sign in to comment.