Skip to content

Commit d328200

Browse files
committed
Tweaks for saving in a modal
1 parent 179fd8d commit d328200

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

client/js/ManyField.src.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,21 @@
8282
var id = parents.attr('id');
8383
var modal = $("#" + id + '_modal');
8484

85-
modal.find('.modal-body').html($(data)
86-
.find('.CompositeField')
87-
.removeClass('manyfield__row').html()
88-
);
85+
// write the provided names as we don't need to namespace them in this
86+
// case - we can only edit one at a time
87+
var content = $(data)
88+
content.find('input[name]').each(function(i, field) {
89+
if ($(field).indexOf('[') !== false) {
90+
var name = $(field).attr('name').substr(
91+
$(field).attr('name').indexOf('[') + 1,
92+
$(field).attr('name').indexOf(']')
93+
);
94+
95+
$(field).attr('name', name);
96+
}
97+
});
8998

99+
modal.find('.modal-body').html(content.html());
90100
modal.modal('show');
91101
} else {
92102
if (rows && rows.length) {
@@ -143,6 +153,7 @@
143153
body.html('');
144154
})
145155
} else {
156+
// highlight issues
146157
e.preventDefault();
147158

148159
return false;
@@ -162,8 +173,22 @@
162173
var saveURL = modal.attr('data-save-url');
163174

164175
$.get(modal.data('form-url'), {RecordID: recordId}, function(data) {
165-
modal.find('.modal-body').html($('<form action="'+ saveURL + '"></form>').html(data)).removeClass('loading');
166-
modal.modal('show');
176+
// write the provided names as we don't need to namespace them in this
177+
// case - we can only edit one at a time
178+
var content = $('<form action="'+ saveURL + '"></form>').html(data)
179+
content.find('input[name]').each(function(i, field) {
180+
if ($(field).indexOf('[') !== false) {
181+
var name = $(field).attr('name').substr(
182+
$(field).attr('name').indexOf('[') + 1,
183+
$(field).attr('name').indexOf(']')
184+
);
185+
186+
$(field).attr('name', name);
187+
}
188+
});
189+
190+
modal.find('.modal-body').html(content).removeClass('loading');
191+
modal.modal('show');
167192
});
168193
})
169194

src/ManyField.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,11 @@ public function SaveLink()
499499
public function setValue($value, $data = null)
500500
{
501501
if (!$value && $data) {
502-
if ($data->hasMethod($this->name)) {
502+
if (is_array($data)) {
503+
if (isset($data[$this->name])) {
504+
$value = $data[$this->name];
505+
}
506+
} else if ($data->hasMethod($this->name)) {
503507
$value = $data->{$this->name}();
504508
}
505509
}

templates/ManyFieldModal.ss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
<div class="modal-footer">
3838
<button type="button" class="btn btn-primary manyfield__save">Save</button>
39-
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
39+
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
4040
</div>
4141
</div><!-- /.modal-content -->
4242
</div><!-- /.modal-dialog -->

templates/ManyFieldModal_holder.ss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
<div class="modal-footer">
3838
<button type="button" class="btn btn-primary manyfield__save">Save</button>
39-
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
39+
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
4040
</div>
4141
</div><!-- /.modal-content -->
4242
</div><!-- /.modal-dialog -->

0 commit comments

Comments
 (0)