mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +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;
|
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
|
||||||
*
|
*
|
||||||
|
@ -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.
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user