BUG Add flag on form whether to notify user when there's unsaved changes

This commit is contained in:
Saophalkun Ponlu 2017-06-21 16:54:54 +12:00 committed by Christopher Joe
parent 2bdb72c0f3
commit 288de2eb14
3 changed files with 26 additions and 1 deletions

View File

@ -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
*

View File

@ -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.

View File

@ -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);