mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-29 04:39:01 +02:00
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:
commit
51e4e4df6d
@ -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
|
||||
*
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user