Skip to content

How to get a list of modified fields in JS when editing entry #10752

Answered by brandonkelly
michaelrog asked this question in Q&A
Discussion options

You must be logged in to vote

Craft JS doesn’t keep a definitive list currently. (The delta stuff is only for keeping track of what has changed on the current page, but doesn’t factor in any preexisting changes on the draft.) The fields themselves know, though. So you could fire an Ajax request that loads the draft and checks each of its fields.

use craft\base\Element;
use craft\elements\Entry;

$draft = Entry::find()
    ->draftId($draftId)
    ->provisionalDrafts(null)
    ->anyStatus() // Craft 3
    ->status(null) // Craft 4
    ->one();

$modifiedFields = [];

foreach ($draft->getFieldLayout()->getFields() as $field) {
    $status = $field->getStatus($draft);
    if ($status && $status[0] === Element::ATTR_STATUS…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants