diff --git a/src/Forms/Form.php b/src/Forms/Form.php index a7254fd98..1aa74cfb4 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -262,6 +262,11 @@ class Form extends ViewableData implements HasRequestHandler */ protected $securityTokenAdded = false; + /** + * @var bool + */ + protected $notifyUnsavedChanges = false; + /** * Create a new form, with the given fields an action buttons. * @@ -309,6 +314,22 @@ class Form extends ViewableData implements HasRequestHandler $this->setupDefaultClasses(); } + /** + * @return bool + */ + public function getNotifyUnsavedChanges() + { + return $this->notifyUnsavedChanges; + } + + /** + * @param bool + */ + public function setNotifyUnsavedChanges($flag) + { + $this->notifyUnsavedChanges = $flag; + } + /** * Load form state from session state * diff --git a/src/Forms/Schema/FormSchema.php b/src/Forms/Schema/FormSchema.php index 0b3235623..6312d2733 100644 --- a/src/Forms/Schema/FormSchema.php +++ b/src/Forms/Schema/FormSchema.php @@ -127,6 +127,7 @@ class FormSchema 'id' => $form->FormName(), 'fields' => [], 'messages' => [], + 'notifyUnsavedChanges' => $form->getNotifyUnsavedChanges(), ]; // flattened nested fields are returned, rather than only top level fields. diff --git a/tests/php/Forms/FormSchemaTest.php b/tests/php/Forms/FormSchemaTest.php index fa7998c02..a3b4ffaf6 100644 --- a/tests/php/Forms/FormSchemaTest.php +++ b/tests/php/Forms/FormSchemaTest.php @@ -55,6 +55,7 @@ class FormSchemaTest extends SapphireTest ] ], 'messages' => [], + 'notifyUnsavedChanges' => false ]; $state = $formSchema->getState($form); @@ -84,6 +85,7 @@ class FormSchemaTest extends SapphireTest 'value' => 'All saved', 'type' => 'good' ]], + 'notifyUnsavedChanges' => false ]; $state = $formSchema->getState($form); @@ -126,7 +128,8 @@ class FormSchemaTest extends SapphireTest 'name' => 'SecurityID', ] ], - 'messages' => [] + 'messages' => [], + 'notifyUnsavedChanges' => false ]; $state = $formSchema->getState($form);