Campi obbligatori & fix

This commit is contained in:
2025-09-08 17:38:47 +02:00
parent cbcbcc6f8e
commit 5dec036e78
13 changed files with 711 additions and 114 deletions

View File

@ -25,7 +25,7 @@ HTMLHelper::_('bootstrap.tooltip');
<form
action="<?php echo Route::_('index.php?option=com_circolari&layout=edit&id=' . (int) $this->item->id); ?>"
method="post" enctype="multipart/form-data" name="adminForm" id="adminForm" class="form-validate" class="form-validate form-horizontal">
method="post" enctype="multipart/form-data" name="adminForm" id="adminForm" class="form-validate form-horizontal">
<?php echo HTMLHelper::_('uitab.startTabSet', 'myTab', array('active' => 'Circolari')); ?>
@ -37,7 +37,6 @@ HTMLHelper::_('bootstrap.tooltip');
<?php echo $this->form->renderField('title'); ?>
<?php echo $this->form->renderField('alias'); ?>
<?php echo $this->form->renderField('categoria_id'); ?>
<?php echo $this->form->renderField('usergroup_id'); ?>
<?php echo $this->form->renderField('hits'); ?>
<?php echo $this->form->renderField('description'); ?>
<?php echo $this->form->renderField('attachment'); ?>
@ -56,4 +55,65 @@ HTMLHelper::_('bootstrap.tooltip');
<?php echo HTMLHelper::_('uitab.endTabSet'); ?>
<input type="hidden" name="task" value="" />
<?php echo HTMLHelper::_('form.token'); ?>
</form>
</form>
<?php
Factory::getDocument()->addScriptDeclaration(<<<'JS'
(function(){
// Supporta sia select che radio per jform_firma_obbligatoria
function getFirmaObbligatoriaValue(){
var radios = document.querySelectorAll('input[name="jform[firma_obbligatoria]"]');
if (radios.length){
var r = Array.prototype.find.call(radios, function(x){ return x.checked; });
return r ? r.value : '0';
}
var sel = document.getElementById('jform_firma_obbligatoria');
return sel ? sel.value : '0';
}
function toggleScadenzaRequired(){
var need = getFirmaObbligatoriaValue() === '1';
var input = document.getElementById('jform_scadenza');
var label = document.getElementById('jform_scadenza-lbl');
if (input){
if (need){
input.setAttribute('required','required');
input.setAttribute('aria-required','true');
} else {
input.removeAttribute('required');
input.removeAttribute('aria-required');
input.classList.remove('invalid');
}
}
if (label){
if (need){
label.classList.add('required');
if (!label.querySelector('.star')){
var s = document.createElement('span');
s.className = 'star';
s.setAttribute('aria-hidden','true');
s.innerHTML = '&nbsp;*';
label.appendChild(s);
}
} else {
label.classList.remove('required');
var star = label.querySelector('.star');
if (star){ star.remove(); }
}
}
}
// Bind change su select/radio
document.addEventListener('change', function(e){
if (e.target && (e.target.id === 'jform_firma_obbligatoria' || e.target.name === 'jform[firma_obbligatoria]')){
toggleScadenzaRequired();
}
});
// Init
document.addEventListener('DOMContentLoaded', toggleScadenzaRequired);
})();
JS);