CTOlet / yii2-attachments

Yii2 extension for uploading and attaching the files to the models
66 stars 57 forks source link

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

Open adiramardiani opened 8 years ago

adiramardiani commented 8 years ago

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

/*example*/
[['field_name'], 'required', 'on' => 'update'],
CTOlet commented 8 years ago

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

adiramardiani commented 8 years ago

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

CTOlet commented 8 years ago

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

adiramardiani commented 8 years ago

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)