Correction gros bug checkbox

This commit is contained in:
Jean-Christophe Engel 2023-10-25 12:14:05 +02:00
parent 50230bc673
commit a28d725d65
1 changed files with 56 additions and 22 deletions

View File

@ -14,14 +14,8 @@
{{:assign var="labels" value=$_POST.input_fields.label}}
{{:assign var="owner_keys" value=$_POST.input_fields.owner|keys}}
{{#foreach from=$labels item="label"}}
{{if $label|in:$owner_keys}}
{{* label présent *}}
{{:assign var="input_fields." label=$label|trim owner=1|boolval}}
{{else}}
{{* label absent *}}
{{:assign var="input_fields." label=$label|trim owner=0|boolval}}
{{/if}}
{{#foreach from=$_POST.input_fields|array_transpose item="field"}}
{{:assign var="input_fields." label=$field.label|trim owner=$field.owner|boolval}}
{{/foreach}}
{{:save key="config"
@ -56,11 +50,17 @@
<th>Action</th>
</tr>
</thead>
<tbody>
<tbody id="input_body">
{{#foreach from=$module.config.inputNature item="input_field"}}
<tr>
<td>{{:input type="text" name="input_fields[label][]" default=$input_field.label}}</td>
<td><label>{{:input type="checkbox" name="input_fields[owner][%s]"|args:$input_field.label value=1 default=$input_field.owner}}oui</label></td>
<td>
<label>
{{:input type="checkbox" name="input_fields[owner][]" value=1 default=$input_field.owner}}
Proprio ?
{{:input type="hidden" name="input_fields[owner][]" value=0}}
</label>
</td>
<td class="action">
{{:button label="Retirer" shape="minus" onclick="this.parentNode.parentNode.remove();"}}
</td>
@ -69,7 +69,13 @@
{{#foreach from=$types_entrees key="label" item="value"}}
<tr>
<td>{{:input type="text" name="input_fields[label][]" default=$label}}</td>
<td><label>{{:input type="checkbox" name="input_fields[owner][]" value=1 default=$value}}oui</label></td>
<td>
<label>
{{:input type="checkbox" name="input_fields[owner][]" value=1 default=$value}}
Proprio ?
{{:input type="hidden" name="input_fields[owner][]" value=0}}
</label>
</td>
<td class="action">
{{:button label="Retirer" shape="minus" onclick="this.parentNode.parentNode.remove();"}}
</td>
@ -81,11 +87,7 @@
<p class="actions">
{{:button shape="plus"
label="Ajouter un champ"
onclick="var a = document.querySelector('.input_fields tbody').lastElementChild;
var b = a.cloneNode(true);
b.querySelector('input[type="text"]').value = null;
b.querySelector('input[type="checkbox"]').checked = false;
a.parentNode.append(b);"}}
onclick="addLine('#input_body')"}}
</p>
</fieldset>
@ -98,7 +100,7 @@
<th>Action</th>
</tr>
</thead>
<tbody>
<tbody id="output_body">
{{#foreach from=$module.config.outputNature item="output_field"}}
<tr>
<td>{{:input type="text" name="output_fields[]" default=$output_field.label}}</td>
@ -121,17 +123,49 @@
<p class="actions">
{{:button shape="plus"
label="Ajouter un champ"
onclick="var a = document.querySelector('.output_fields tbody').lastElementChild;
var b = a.cloneNode(true);
b.querySelector('input[type="text"]').value = null;
a.parentNode.append(b);"}}
onclick="addLine('#output_body')"}}
</p>
</fieldset>
<p class="submit">
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
{{:button
type="submit"
name="save"
label="Enregistrer"
shape="right"
class="main"
onclick="return desactiverCache('#input_body');"
}}
</p>
</form>
<script type="text/javascript">
// dupliquer la dernière ligne d'une table
function addLine(id_body) {
var ligne = document.querySelector(id_body).lastElementChild;
var nelle = ligne.cloneNode(true);
let text = nelle.querySelector('input[type="text"]');
text.value = null;
let cb = nelle.querySelector('input[type="checkbox"]')
if (cb != null) {
cb.checked = false;
}
ligne.parentNode.appendChild(nelle);
text.focus();
}
// Désactiver les champs caché des checkbox cochés
function desactiverCache(id_body) {
var table = document.querySelector(id_body);
let lignes = table.children;
for (let i = 0; i < lignes.length; ++i) {
let idCase = lignes[i].querySelector("input[type=checkbox]");
let cache = lignes[i].querySelector("input[type=hidden]"); // le champ caché
if (idCase.checked) {
cache.disabled = true;
}
}
}
</script>
{{:admin_footer}}