yii2-attachments icon indicating copy to clipboard operation
yii2-attachments copied to clipboard

How to set required (must be set) on upload form

Open adiramardiani opened this issue 9 years ago • 4 comments

In rule is provided FileValidator, how to add a required option ?

/*example*/
[['field_name'], 'required', 'on' => 'update'],

adiramardiani avatar Feb 11 '16 22:02 adiramardiani

Does it work if you set the rules inside app config?

'modules' => [
    ...
    'attachments' => [
        'class' => nemmo\attachments\Module::className(),
        'rules' => [ // Rules according to the FileValidator
            'maxFiles' => 10, // Allow to upload maximum 3 files, default to 3
            'mimeTypes' => 'image/png', // Only png images
            'maxSize' => 1024 * 1024 // 1 MB
        ],
    ]
    ...
]

But I think it will not work. Thus it will be an enhancement. Added to checklist #36

CTOlet avatar Feb 15 '16 04:02 CTOlet

Yes I did not try it inside the app config But what kind of method that can do that ?

It's so I need at this moment, if you could explain a temporary method that allows this currently ? while I waited for the enhancement

Thanks

adiramardiani avatar Feb 15 '16 13:02 adiramardiani

You can fork or download the whole module and add this feature inside file behavior. I think the right way is to check the file existance on before save event

CTOlet avatar Feb 15 '16 14:02 CTOlet

Sorry, add this feature inside file behavior or check the file existance on before save event, I can't understand how to write it, I was newbie, can you also explain the example code.

(While waiting in the newest version for the best method)

adiramardiani avatar Feb 16 '16 14:02 adiramardiani