Skip to content

Commit 7ab6fbc

Browse files
committed
fix(form): avoid useless HTTP requests and php warning
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent d79ff8d commit 7ab6fbc

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

inc/question.class.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,19 @@ public function setRequired($isRequired) {
555555
* @param array $input parameters
556556
*/
557557
public function updateParameters($input) {
558+
// The question instance has a field type
558559
if (!isset($this->fields['fieldtype'])) {
559560
return;
560561
}
562+
$fieldType = $this->fields['fieldtype'];
563+
564+
// The fieldtype may change
565+
if (isset($input['fieldtype'])) {
566+
$fieldType = $input['fieldtype'];
567+
}
561568

562569
$this->field = PluginFormcreatorFields::getFieldInstance(
563-
$input['fieldtype'],
570+
$fieldType,
564571
$this
565572
);
566573
$this->field->updateParameters($this, $input);

js/scripts.js.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,16 @@ function buildTiles(list) {
445445
this.initialPosition = {};
446446
this.changingItemId = 0;
447447
this.questionsColumns = <?php echo PluginFormcreatorSection::COLUMNS; ?>;
448+
this.dirty = false;
448449

449450
this.setupGridStack = function (group) {
451+
var that = this;
450452
group
451453
.on('resizestart', this.startChangeItem)
452454
.on('dragstart', this.startChangeItem)
453-
.on('change', this.changeItems)
455+
.on('change', function(event, item) {
456+
that.changeItems(event, item)
457+
})
454458
.on('dragstop', function(event, item) {
455459
setTimeout(function() {
456460
item.helper.find('a').off('click.prevent');
@@ -462,6 +466,7 @@ function buildTiles(list) {
462466
};
463467

464468
this.initGridStack = function (sectionId) {
469+
var that = this;
465470
var group = $('#plugin_formcreator_form.plugin_formcreator_form_design [data-itemtype="PluginFormcreatorSection"][data-id="' + sectionId + '"] .grid-stack');
466471
group.gridstack({
467472
width: this.questionsColumns,
@@ -482,6 +487,7 @@ function buildTiles(list) {
482487
}
483488
}).success(function(data, httpCode) {
484489
var grid = group.data('gridstack');
490+
that.dirty = true;
485491
$.each(data, function(index, question) {
486492
grid.addWidget(
487493
question.html,
@@ -496,6 +502,7 @@ function buildTiles(list) {
496502
1
497503
);
498504
});
505+
that.dirty = false;
499506
}).complete(this.setupGridStack(group));
500507
};
501508

@@ -519,17 +526,15 @@ function buildTiles(list) {
519526
}
520527
});
521528
this.changingItemId = Number($(event.target).attr('data-id'));
522-
this.dirty = false;
523529
};
524530

525531
/**
526532
* Event handler : change an item (resize or move)
527533
*/
528534
this.changeItems = function (event, items) {
529535
if (this.dirty === true) {
530-
//return;
536+
return;
531537
}
532-
this.dirty = true;
533538
var that = this;
534539
var changes = {};
535540
$.each(items, function(index, item) {

0 commit comments

Comments
 (0)