Merge pull request #7045 from open-sausages/pulls/4.0/selective-form-unsaved-change-notification

BUG Add flag on form whether to notify user when there's unsaved changes
This commit is contained in:
Chris Joe 2017-06-28 15:36:33 +12:00 committed by GitHub
commit 51e4e4df6d
3 changed files with 26 additions and 1 deletions

View File

@ -262,6 +262,11 @@ class Form extends ViewableData implements HasRequestHandler
*/ */
protected $securityTokenAdded = false; protected $securityTokenAdded = false;
/**
* @var bool
*/
protected $notifyUnsavedChanges = false;
/** /**
* Create a new form, with the given fields an action buttons. * Create a new form, with the given fields an action buttons.
* *
@ -309,6 +314,22 @@ class Form extends ViewableData implements HasRequestHandler
$this->setupDefaultClasses(); $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 * Load form state from session state
* *

View File

@ -127,6 +127,7 @@ class FormSchema
'id' => $form->FormName(), 'id' => $form->FormName(),
'fields' => [], 'fields' => [],
'messages' => [], 'messages' => [],
'notifyUnsavedChanges' => $form->getNotifyUnsavedChanges(),
]; ];
// flattened nested fields are returned, rather than only top level fields. // flattened nested fields are returned, rather than only top level fields.

View File

@ -55,6 +55,7 @@ class FormSchemaTest extends SapphireTest
] ]
], ],
'messages' => [], 'messages' => [],
'notifyUnsavedChanges' => false
]; ];
$state = $formSchema->getState($form); $state = $formSchema->getState($form);
@ -84,6 +85,7 @@ class FormSchemaTest extends SapphireTest
'value' => 'All saved', 'value' => 'All saved',
'type' => 'good' 'type' => 'good'
]], ]],
'notifyUnsavedChanges' => false
]; ];
$state = $formSchema->getState($form); $state = $formSchema->getState($form);
@ -126,7 +128,8 @@ class FormSchemaTest extends SapphireTest
'name' => 'SecurityID', 'name' => 'SecurityID',
] ]
], ],
'messages' => [] 'messages' => [],
'notifyUnsavedChanges' => false
]; ];
$state = $formSchema->getState($form); $state = $formSchema->getState($form);