Disable post message required validation when post has attached files (#7151)

* Disable post message required validation when post has attached files

* Disable post message required validation when post has attached files
This commit is contained in:
Gevorg Mansuryan 2024-08-02 11:46:50 +04:00 committed by GitHub
parent 1a4d186c75
commit 7625750d4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 2 deletions

View File

@ -14,6 +14,7 @@ HumHub Changelog
- Enh #7138: Added missing DB relations to UserInvite model
- Enh #7139 : Export `confirmUnload` function from `humhub.client.js`
- Enh #7144: Add `DeviceDetectorHelper` class to detect devices such as the mobile app
- Fix #7151: Disable new post's required validation for `message` when post has attached files
1.16.2 (Unreleased)
---------------------

View File

@ -80,6 +80,10 @@ class PostController extends ContentContainerController
$post->load(Yii::$app->request->post(), 'Post');
if (!empty(Yii::$app->request->post('fileList'))) {
$post->scenario = Post::SCENARIO_HAS_FILES;
}
return Post::getDb()->transaction(function ($db) use ($post) {
return WallCreateContentForm::create($post, $this->contentContainer);
});

View File

@ -44,10 +44,15 @@ class Post extends ContentActiveRecord
public $canMove = CreatePost::class;
/**
* Scenarios
* Scenario - when validating with ajax
*/
public const SCENARIO_AJAX_VALIDATION = 'ajaxValidation';
/**
* Scenario - when related content has attached files
*/
public const SCENARIO_HAS_FILES = 'hasFiles';
/**
* @inheritdoc
*/
@ -67,7 +72,7 @@ class Post extends ContentActiveRecord
public function rules()
{
return [
[['message'], 'required', 'except' => self::SCENARIO_AJAX_VALIDATION],
[['message'], 'required', 'except' => [self::SCENARIO_AJAX_VALIDATION, self::SCENARIO_HAS_FILES]],
[['message'], 'string'],
[['url'], 'string', 'max' => 255],
];