Skip to content

Commit 179fd8d

Browse files
committed
Correct saving in modals
1 parent d242ac7 commit 179fd8d

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

client/js/ManyField.src.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
$('body').on('click', '.manyfield__save', function(e) {
134134
var form = $(this).parents('.modal-content').find('form');
135135

136-
if (form.checkValidity()) {
136+
if (form.get(0).checkValidity()) {
137137
var body = $(this).parents('.modal-content').find('.modal-body')
138138
.addClass('loading')
139139

@@ -144,6 +144,8 @@
144144
})
145145
} else {
146146
e.preventDefault();
147+
148+
return false;
147149
}
148150
})
149151

@@ -157,9 +159,10 @@
157159
// find the add modal, set the content to that and open it.
158160
var id = parents.attr('id');
159161
var modal = $('#' + id + '_modal');
162+
var saveURL = modal.attr('data-save-url');
160163

161164
$.get(modal.data('form-url'), {RecordID: recordId}, function(data) {
162-
modal.find('.modal-body').html(data).removeClass('loading');
165+
modal.find('.modal-body').html($('<form action="'+ saveURL + '"></form>').html(data)).removeClass('loading');
163166
modal.modal('show');
164167
});
165168
})

src/ManyField.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ public function AddLink()
468468
}
469469

470470
/**
471-
* Add URL
471+
* Edit Record Form URL
472472
*
473473
* @return string
474474
*/
@@ -480,6 +480,19 @@ public function EditLink()
480480
);
481481
}
482482

483+
/**
484+
* Save Record Form URL
485+
*
486+
* @return string
487+
*/
488+
public function SaveLink()
489+
{
490+
return Controller::join_links(
491+
$this->AbsoluteLink('saveRecord'),
492+
'?SecurityID='. SecurityToken::inst()->getValue() . '&ClassName=' . $this->value->dataClass()
493+
);
494+
}
495+
483496
/**
484497
* Override set value.
485498
*/

templates/ManyFieldModal.ss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</div>
2222
<% end_if %>
2323

24-
<div class="modal" id="{$HolderID}_modal" data-form-url="$EditLink">
24+
<div class="modal" id="{$HolderID}_modal" data-form-url="$EditLink" data-save-url="$SaveLink">
2525
<div class="modal-dialog modal-lg" role="document">
2626
<div class="modal-content">
2727
<div class="modal-header">
@@ -35,7 +35,7 @@
3535
</div>
3636

3737
<div class="modal-footer">
38-
<button type="button" class="btn btn-primary manyfield__save" data-dismiss="modal">Save</button>
38+
<button type="button" class="btn btn-primary manyfield__save">Save</button>
3939
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
4040
</div>
4141
</div><!-- /.modal-content -->

templates/ManyFieldModal_holder.ss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</div>
2222
<% end_if %>
2323

24-
<div class="modal" id="{$HolderID}_modal" data-form-url="$EditLink">
24+
<div class="modal" id="{$HolderID}_modal" data-form-url="$EditLink" data-save-url="$SaveLink">
2525
<div class="modal-dialog modal-lg" role="document">
2626
<div class="modal-content">
2727
<div class="modal-header">
@@ -35,7 +35,7 @@
3535
</div>
3636

3737
<div class="modal-footer">
38-
<button type="button" class="btn btn-primary manyfield__save" data-dismiss="modal">Save</button>
38+
<button type="button" class="btn btn-primary manyfield__save">Save</button>
3939
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
4040
</div>
4141
</div><!-- /.modal-content -->

0 commit comments

Comments
 (0)