mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-20 17:24:25 +00:00
Prevent leaving the new and edit report page without saving. close #319
Code inspired by http://stackoverflow.com/a/21061009/1572236 I think this functionality might be interesting for other forms. Maybe we could abstract them in a twig template to reuse the code (with an 'include' declaration) or add this to all form automatically, by customizing the form_start or form_end function ?
This commit is contained in:
parent
2eb2214921
commit
c169269876
@ -29,4 +29,23 @@
|
|||||||
<button class="sc-button red" type="reset"><i class="fa fa-eraser"></i> {{ 'Reset report'|trans }}</button>
|
<button class="sc-button red" type="reset"><i class="fa fa-eraser"></i> {{ 'Reset report'|trans }}</button>
|
||||||
</div>
|
</div>
|
||||||
{{ form_end(edit_form) }}
|
{{ form_end(edit_form) }}
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
var form = $("form[name='{{ edit_form.vars.form.vars.name }}']").data('serialize',$("form[name='{{ edit_form.vars.form.vars.name }}']").serialize());
|
||||||
|
// On load save form current state
|
||||||
|
var submittedOk{{ edit_form.vars.form.vars.name }} = false;
|
||||||
|
form.bind('submit', function(e) {
|
||||||
|
submittedOk{{ edit_form.vars.form.vars.name }} = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).bind('beforeunload', function(e){
|
||||||
|
if($("form[name='{{ edit_form.vars.form.vars.name }}']").serialize()!=$("form[name='{{ edit_form.vars.form.vars.name }}']").data('serialize')){
|
||||||
|
if (submittedOk{{ edit_form.vars.form.vars.name }} == false) {
|
||||||
|
return "{{ 'You are going to leave a page with unsubmitted data. Are you sure you want to leave ?'|trans }}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e=null;
|
||||||
|
// i.e; if form state change show box not.
|
||||||
|
});
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -29,4 +29,22 @@
|
|||||||
<button class="sc-button red" type="reset"><i class="fa fa-eraser"></i> {{ 'Reset report'|trans }}</button>
|
<button class="sc-button red" type="reset"><i class="fa fa-eraser"></i> {{ 'Reset report'|trans }}</button>
|
||||||
</div>
|
</div>
|
||||||
{{ form_end(form) }}
|
{{ form_end(form) }}
|
||||||
|
<script type="text/javascript">
|
||||||
|
var form = $("form[name='{{ form.vars.form.vars.name }}']").data('serialize',$("form[name='{{ form.vars.form.vars.name }}']").serialize());
|
||||||
|
// On load save form current state
|
||||||
|
var submittedOk{{ form.vars.form.vars.name }} = false;
|
||||||
|
form.bind('submit', function(e) {
|
||||||
|
submittedOk{{ form.vars.form.vars.name }} = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).bind('beforeunload', function(e){
|
||||||
|
if($("form[name='{{ form.vars.form.vars.name }}']").serialize()!=$("form[name='{{ form.vars.form.vars.name }}']").data('serialize')){
|
||||||
|
if (submittedOk{{ form.vars.form.vars.name }} == false) {
|
||||||
|
return "{{ 'You are going to leave a page with unsubmitted data. Are you sure you want to leave ?'|trans }}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e=null;
|
||||||
|
// i.e; if form state change show box not.
|
||||||
|
});
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user