Validation always required on drafts/revisions

オープン
#15,995 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
28/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
laravel, php, yaml
領域
backend

調査の方向性

Start in the Blueprint field's Field::rules(), which the issue names as the place where the 'Required' toggle is prepended, then follow where entry validation runs on publish versus draft/working-copy saves. Read the closed PR #8919 and the linked ideas#765 for the earlier attempt that skipped all validation on drafts, since that is the behaviour being narrowed. Expect a decision on how the required toggle interacts with the marker before any patch; done means drafts skip marked rules while published saves and publishing a working copy still run them, with tests covering users/terms/globals which must ignore the marker.

索引モデルが issue の本文から書いたものです。

説明

needs decision
Bug description

Saving a draft, or a working copy when revisions are on, runs every validation rule. An editor can't save an entry that is still missing a required field, even though nobody can see it yet.

A typical case: a client starts an entry before they have the hero image or the final copy. The image is required, so the save fails. They end up uploading a placeholder or leaving the tab open.

How to reproduce
  1. Add a required field to a collection blueprint, e.g. an assets field.
  2. Create an entry, fill in only the title, and leave it unpublished.
  3. Save. It fails with "This field is required."
Logs

No response

Environment
Statamic 6.43.1 PRO
Installation

Fresh statamic/statamic site via CLI

Additional details

Proposal

Use the special rule Jason suggested when closing #8919 (https://github.com/statamic/cms/pull/8919#issuecomment-1994513035): a when_publishing marker in a field's validate rules. Rules listed above when_publishing always run. Rules listed below it are skipped on drafts and only run when the entry is published.

validate:
  - 'max:5'
  - when_publishing
  - required
  - 'min:2'

The details we'd suggest:

  • It only affects rules listed in validate. A fieldtype's own rules always run, so an integer field still has to be an integer on a draft.
  • Marked rules run when saving a published entry or publishing a working copy. They're skipped when saving a draft or a working copy.
  • The "Required" toggle is added ahead of the validate rules in Field::rules(), so it can never fall after the marker. This needs a decision. One option: when the marker is present, treat the toggle as publish-only too.
  • Title stays required unless the collection has a title format, as it is today.
  • Blueprints with no published state (users, terms, globals) ignore the marker and always run every rule.
  • It's opt-in per field, so it isn't breaking and could go in 6.x. Whether drafts should skip required by default is a separate question for 7.x.

Related

  • #8919: the closed PR that skipped all validation on drafts.
  • statamic/ideas#765: the same request for working copies.
  • #10515: autosave can't start on a new entry.
主要言語
PHP
スター
4.9k
フォーク
647
平均マージ
1日 45分
マージ済み PR(30日)
221

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

statamic/cms のほかの issue

statamic/cms の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。