Commit 28f5e5dd authored by Théo GUILLON's avatar Théo GUILLON
Browse files

Correction : champ radio

Correction : champ multi-select
Correction : affichage conditions
Ajout : mise en place des conditions sur le formulaire
parent e814cc64
......@@ -273,34 +273,47 @@ $line = 1;
// Mise en place des conditions
var conditions = <?php echo json_encode($conditions); ?>;
$.each(conditions, function (key, value) {
if (value['ifNot'] == 'shown') {
$('#' + value['thenTheField']).parent().parent().show();
} else {
$('#' + value['thenTheField']).parent().parent().hide();
}
shownHideField(value['ifNot'], value['thenTheField']);
$('#'+value['ifTheField']).change(function(){
var val = $(this).val();
if (jQuery.inArray(value['ifTheField'], ['transfertHorsUe', 'donneesSensible']) !== -1) {
if ($('#' + value['ifTheField']).val() == value['hasValue']) {
shownHideField(value['mustBe'], value['thenTheField'])
} else {
shownHideField(value['ifNot'], value['thenTheField']);
}
if (val == value['hasValue']) {
if (value['mustBe'] == 'shown') {
$('#' + value['thenTheField']).parent().parent().show();
$('#' + value['ifTheField']).change(function () {
if ($(this).val() == value['hasValue']) {
shownHideField(value['mustBe'], value['thenTheField'])
} else {
$('#' + value['thenTheField']).parent().parent().hide();
shownHideField(value['ifNot'], value['thenTheField']);
}
});
} else {
if ($('#' + value['hasValue']).prop("checked") == true) {
shownHideField(value['mustBe'], value['thenTheField'])
} else {
if (value['ifNot'] == 'shown') {
$('#' + value['thenTheField']).parent().parent().show();
shownHideField(value['ifNot'], value['thenTheField']);
}
$('#' + value['hasValue']).on('change', function () {
if ($(this).prop("checked") == true) {
shownHideField(value['mustBe'], value['thenTheField'])
} else {
$('#' + value['thenTheField']).parent().parent().hide();
shownHideField(value['ifNot'], value['thenTheField']);
}
}
});
});
}
});
function createConditions(value)
function shownHideField(condition, thenTheField)
{
if (condition == 'shown') {
$('#' + thenTheField).parent().parent().show();
} else {
$('#' + thenTheField).parent().parent().hide();
$('#' + thenTheField).val('');
}
}
});
</script>
\ No newline at end of file
......@@ -210,8 +210,8 @@ foreach ($champs as $key => $value) {
.'</label>'
.'</div>'
.'<div class="col-md-8">'
.'<input id="'.$details['name'].'" type="hidden" name="'.$details['name'].'" value=""/>'
.'<select id="'.$details['name'].'" name="multi-select" class="form-control multiSelect contentMultiSelect" multiple="multiple">';
.'<input id="'.$details['name'].'_" type="hidden" name="'.$details['name'].'" value=""/>'
.'<select name="'.$details['name'].'" class="form-control multiSelect contentMultiSelect" multiple="multiple">';
foreach ($details['options'] as $key => $val) {
$selected = "";
if (isset($details['default'])) {
......
......@@ -181,8 +181,10 @@
// On recupere les "options" du champ "selected" sur lequel nous allons faire la condition
$(idContainer).find('input[name ="'+idFieldConditionCreated+'"], option[name ="'+idFieldConditionCreated+'"]').each(function () {
var option = $(this).attr('value');
if (option) {
$('#hasValue').append('<option value="' + option + '">' + option + '</option>');
var id = $(this).attr('id');
if (option && id) {
$('#hasValue').append('<option value="' + id + '">' + option + '</option>');
}
});
}
......
......@@ -922,8 +922,7 @@ var createForm = function(typeCreateForm) {
}
if (!hasValue) {
var val_id = $('input[value="'+value['hasValue']+'"]').attr('id');
hasValue = $('label[for="'+val_id+'"]').text();
hasValue = $('#'+value['hasValue']).labels().text();
}
if (value['mustBe'] == 'shown') {
......@@ -1112,7 +1111,7 @@ var createForm = function(typeCreateForm) {
objet = objet + '<input id="'+newNameField+'" type="hidden" name="'+newNameField+'" value="">'
$.each(newOptionsField, function (index, value) {
objet = objet + '<div class="radio">' +
'<input id="'+index+'" type="radio" name="'+newNameField+'" value="'+value+'">' +
'<input id="'+newNameField+index+'" type="radio" name="'+newNameField+'" value="'+value+'">' +
value +
'</div>';
});
......@@ -1146,6 +1145,11 @@ var createForm = function(typeCreateForm) {
'</option>';
});
// add attribute "id"
$(idContainer).find('.ui-selected').find('input[type="hidden"]').attr('id', newNameField);
$(idContainer).find('.ui-selected').find('input[type="hidden"]').attr('name', newNameField);
$(idContainer).find('.ui-selected').find('select').attr('name', newNameField);
// give to field the options
$(idContainer).find('.ui-selected').find('.contentMultiSelect').html(jQuery(objet));
}
......
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