feat: ✨ add support of file input in dynamic fields
This commit is contained in:
parent
3f6b4fe97e
commit
29883d3647
7 changed files with 38 additions and 7 deletions
|
|
@ -59,7 +59,7 @@ enum DynamicFieldTypes: int
|
|||
self::email->name => 'required|email:rfc,strict,dns,spoof,filter',
|
||||
self::image->name => 'required|file|mimes:jpg,jpeg,png,pdf|max:5120|dimensions:width=100,height=100',
|
||||
self::list->name => 'required|array|min:1|max:10',
|
||||
self::file->name => 'required|file|mimes:jpg,jpeg,png,pdf|max:5120|dimensions:width=100,height=100',
|
||||
self::file->name => 'required|file|mimes:pdf|max:5120',
|
||||
self::vimeoId->name => 'required|string|min:8|max:10',
|
||||
self::youtubeId->name => 'required|string|size:11',
|
||||
self::date->name => 'required|date',
|
||||
|
|
|
|||
|
|
@ -144,6 +144,12 @@ abstract class UpdateDynamicFieldRequest extends FormRequest
|
|||
$rules = array_merge($rules, $this->recursiveRules($children, $ruleKey . ".*"));
|
||||
}
|
||||
break;
|
||||
case DynamicFieldTypes::file->value:
|
||||
$imgRules = $this->compileValidate(DynamicFieldTypes::file->getValidation(), $input);
|
||||
$rules = array_merge($rules, [
|
||||
$ruleKey => $this->pictureRules(implode("|", $imgRules)),
|
||||
]);
|
||||
break;
|
||||
case DynamicFieldTypes::date->value:
|
||||
$rules = array_merge($rules, [
|
||||
$ruleKey => $this->compileValidate(DynamicFieldTypes::date->getValidation(), $input)
|
||||
|
|
|
|||
|
|
@ -232,6 +232,7 @@ return [
|
|||
"status" => "status",
|
||||
"path" => "path",
|
||||
"label" => "label",
|
||||
"file" => "file",
|
||||
"view" => "spécific view",
|
||||
"parent_page" => "page parente",
|
||||
"config" => "configuration",
|
||||
|
|
|
|||
|
|
@ -233,6 +233,7 @@ return [
|
|||
"unpublished_at" => "dépublié le",
|
||||
"status" => "statut",
|
||||
"label" => "libellé",
|
||||
"file" => "fichier",
|
||||
"view" => "vue spécifique",
|
||||
"config" => "configuration",
|
||||
"type" => "type",
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import SimpleString from "@/back/Components/Inputs/SimpleString";
|
|||
import SimpleNumber from "@/back/Components/Inputs/SimpleNumber";
|
||||
import SimpleSwitch from "@/back/Components/Inputs/SimpleSwitch";
|
||||
import SimpleWysiwyg from "@/back/Components/Inputs/SimpleWysiwyg";
|
||||
import ImageCropperWrapper from "@/back/Components/Inputs/CompleteInputFile";
|
||||
import CompleteInputFile from "@/back/Components/Inputs/CompleteInputFile";
|
||||
import DynamicList from "@/back/Components/DynamicPages/DynamicList";
|
||||
import SimpleTextarea from "@/back/Components/Inputs/SimpleTextarea";
|
||||
import SimpleDatePicker from "@/back/Components/Inputs/SimpleDatePicker";
|
||||
|
|
@ -154,7 +154,7 @@ export default function DynamicInputs({
|
|||
// Image input.
|
||||
case enumDynamicFieldTypes.image.value:
|
||||
return (
|
||||
<ImageCropperWrapper
|
||||
<CompleteInputFile
|
||||
key={id}
|
||||
fileName="fichier"
|
||||
name={fieldName}
|
||||
|
|
@ -201,6 +201,29 @@ export default function DynamicInputs({
|
|||
isChildren={isChildren}
|
||||
/>
|
||||
);
|
||||
// File input.
|
||||
case enumDynamicFieldTypes.file.value:
|
||||
return (
|
||||
<CompleteInputFile
|
||||
key={id}
|
||||
name={fieldName}
|
||||
label={str(
|
||||
useTrans("back.form_associate_to", {
|
||||
params: {
|
||||
attribute: useTrans("validation.custom.file"),
|
||||
},
|
||||
choice: 1,
|
||||
}),
|
||||
).ucFirst().value()}
|
||||
setData={setData}
|
||||
reset={reset}
|
||||
value={fieldValue as string | File | null}
|
||||
required={extractRequiredValidation(field.validation)}
|
||||
maxFileSize={extractLaravelValidationValue(field.validation, 'max')}
|
||||
allowedFormats={extractLaravelValidationValue(field.validation, 'mimes')}
|
||||
inputType={enumDynamicFieldTypes.file.value}
|
||||
/>
|
||||
)
|
||||
// Date picker.
|
||||
case enumDynamicFieldTypes.date.value:
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ type FileWithPreview = FileWithPath & {
|
|||
};
|
||||
|
||||
/* eslint-disable no-unused-vars, @typescript-eslint/no-unused-vars */
|
||||
type ImageCropperWrapperProps = FileValidation & {
|
||||
type CompleteInputFileProps = FileValidation & {
|
||||
name: string;
|
||||
value?: string | File | null;
|
||||
label?: string;
|
||||
|
|
@ -33,7 +33,7 @@ type ImageCropperWrapperProps = FileValidation & {
|
|||
};
|
||||
/* eslint-enable no-unused-vars, @typescript-eslint/no-unused-vars */
|
||||
|
||||
export default function ImageCropperWrapper(props: ImageCropperWrapperProps) {
|
||||
export default function CompleteInputFile(props: CompleteInputFileProps) {
|
||||
const enumDynamicFieldTypes = usePage().props.enumDynamicFieldTypes as DynamicFieldTypes;
|
||||
const {
|
||||
value,
|
||||
|
|
|
|||
|
|
@ -380,7 +380,7 @@ export default function Form({
|
|||
key={dynamicKey}
|
||||
fileName="picture"
|
||||
modelRoute="news"
|
||||
name={"picture"}
|
||||
name="picture"
|
||||
label={str(
|
||||
useTrans("back.form_associate_to", {
|
||||
params: {
|
||||
|
|
@ -393,7 +393,7 @@ export default function Form({
|
|||
reset={reset}
|
||||
value={data.picture}
|
||||
required={true}
|
||||
maxFileSize={"5120"}
|
||||
maxFileSize="5120"
|
||||
allowedFormats={isGif ? 'gif' : "jpg,jpeg,png,webp"}
|
||||
validationRules={isGif ? null : {
|
||||
width: "525",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue