Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Forms/ColorPickerField.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ public function getSourceValues()
}, $this->getSource()));
}

public function Field($properties = [])
{
// Prevent false “unsaved changes” warnings in the CMS by rendering
// a hidden input immediately. This ensures the field value is present
// in the initial DOM snapshot before React mounts.
$schema = parent::Field($properties);

$name = $this->getName();
$value = htmlspecialchars($this->Value() ?? '', ENT_QUOTES);
$hidden = "<input type=\"hidden\" name=\"{$name}\" value=\"{$value}\" />";

return $schema . $hidden;
}

/**
* Return the value of this field (for SilverStripe 6 compatibility)
*/
Expand Down