Commit 181497a5 authored by Théo GUILLON's avatar Théo GUILLON
Browse files

Correction : déplacement des champs dans le formulaire

Correction : de l'envoie de l'utilisation des options à l'ajout d'un formulaire
parent b344381f
......@@ -684,7 +684,7 @@ class FormulairesController extends AppController {
];
if (empty($this->request->data)) {
if ($formulaireOLD === false) {
if ($formulaireOLD === false && $this->request->params['action'] === 'edit') {
$this->request->data = $this->Formulaire->find('first', [
'conditions' => [
'id' => $formulaire_id
......
var createForm = function(typeCreateForm) {
var idContainer = '#form-container-'+typeCreateForm;
var hiddenForm = '#hidden-form-'+typeCreateForm;
var fieldOptions = '#field-options-'+typeCreateForm;
var idbtnApplicable = 'applicable-'+typeCreateForm;
var idbtnCloser = 'closer-'+typeCreateForm;
......@@ -10,10 +9,37 @@ var createForm = function(typeCreateForm) {
var fixmeOffset = 35;
var incrementationId = 0;
var nomVariable = true;
// -------------------------------------------------
jQuery.fn.extend(
{
snapToGrid: function() {
return this.each(function() {
var size = Math.round($(this).closest('.form-container').width() / 2);
$(this).draggable({
containment: 'parent',
grid: [size, 35],
snapTolerance: 35
});
});
}
}
);
$(window).resize(function() {
$(idContainer)
.find('.draggable')
.snapToGrid();
});
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var target = $(e.target).attr("href");
$(target)
.find('.draggable')
.snapToGrid();
});
refresh();
$(idContainer).resizable({
......@@ -21,10 +47,9 @@ var createForm = function(typeCreateForm) {
});
var repositionFieldOnGrid = function(field) {
var container = $(idContainer),
snapTolerance = $(field).draggable('option', 'snapTolerance'),
var snapTolerance = $(field).draggable('option', 'snapTolerance'),
top = (Math.round($(field).position().top) - (Math.round($(field).position().top % snapTolerance))),
left = (Math.round($(field).position().left) < Math.round($(container).width() / 2)) ? 0 : (Math.round(($(container).width() / 2) + 1));
left = (Math.round($(field).position().left + snapTolerance) <= Math.round($(idContainer).width() / 2)) ? 0 : (Math.round(($(idContainer).width() / 2) + 1));
field.css({ 'left': left + 'px', 'top': top + 'px'});
};
......@@ -281,6 +306,7 @@ var createForm = function(typeCreateForm) {
resizeFormContainer();
repositionFieldOnGrid(newElement);
$(newElement).snapToGrid();
for (var i = 0; i < incrementationId; i++) {
$('#datetimepicker' + i).datetimepicker({
......@@ -307,8 +333,7 @@ var createForm = function(typeCreateForm) {
draggableClass.unbind('click');
$(idContainer).unbind('click');
size = $(idContainer).width();
size = Math.round(size / 2);
size = Math.round($(idContainer).width() / 2);
draggableClass.draggable({
containment: 'parent',
......@@ -363,6 +388,12 @@ var createForm = function(typeCreateForm) {
findType = '',
fieldRepeat = '';
// Réinitialisation des champs de la modal concernant l'ajout d'une condition sur un champs
$('#ifTheNameField').val('');
$('#ifTheLadelField').val('');
$('#hasAsValue option').not(':first').remove();
$('#thenTheField option').not(':first').remove();
var btnGoupsTrashApplicable = '<div class="row">' +
'<div class="col-md-12 text-center">' +
'<div class="btn-group">' +
......@@ -494,9 +525,9 @@ var createForm = function(typeCreateForm) {
classListeValeur = '',
nameNomDeVariable = '',
forLabelNomDuChamp = '',
idListeDesValeurs = ''
btnAddConditions = ''
showBtnAddCondition = false
idListeDesValeurs = '',
btnAddConditions = '',
showBtnAddCondition = false,
nameFieldSelected = null;
if ( (object.hasClass('checkboxes')) || (object.hasClass('radios')) ) {
......@@ -900,6 +931,14 @@ var createForm = function(typeCreateForm) {
$(idContainer).find('.ui-selected').find('h5').html(newContenuField);
}
});
// $(idContainer).find('.ui-selected').attr('style', function (i, style) {
// return style.replace(/height[^;]+;?/g, '');
// });
// $(idContainer).find('.ui-selected').attr('style', function (i, style) {
// return style.replace(/width[^;]+;?/g, '');
// });
});
/*Supprimer le champ en question au clic*/
......
......@@ -214,7 +214,6 @@ $(document).ready(function () {
if (success) {
$.each(dynamicFields, function(idx, hidden) {
console.log(hidden);
$('form').append(hidden);
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment