diff --git a/LICENSE.txt b/LICENSE.txt index 8fb3d2c..cc45764 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (C) 2018-2022, Michele Giorgi +Copyright (C) 2018-2023, Michele Giorgi GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 diff --git a/README.md b/README.md index b15b8ad..cce7467 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ If you are not a developer, please download the latest release of the Formality ## Requirements -* [WordPress](https://wordpress.org/) >= 6.0 +* [WordPress](https://wordpress.org/) >= 6.1 ## Plugin setup @@ -54,4 +54,4 @@ Contributions are welcome from everyone. ## License -GPL-3.0 - Copyright (c) 2018-2022 Michele Giorgi +GPL-3.0 - Copyright (c) 2018-2023 Michele Giorgi diff --git a/assets/scripts/public/modules/conditional.js b/assets/scripts/public/modules/conditional.js index e5856a7..272479b 100644 --- a/assets/scripts/public/modules/conditional.js +++ b/assets/scripts/public/modules/conditional.js @@ -4,7 +4,7 @@ export let initConditionalField = (form, field) => { if(!field.hasAttribute('data-conditional')) return let query = '' const rule = JSON.parse(field.getAttribute('data-conditional')) - for (const index in rule) { query += ( index == 0 ? '' : ', ' ) + '[name="' + rule[index].field + '"]' } + for(const index in rule) { query += ( index == 0 ? '' : ', ' ) + '[name="' + rule[index].field + '"]' } if(query) { checkCondition(form, field, rule) const inputs = form.querySelectorAll(query) @@ -23,13 +23,19 @@ export let checkCondition = (form, field, rule, auto=true) => { if(inputs.length) { let check = false let inputValue = '' - inputs.forEach((input)=> { + inputs.forEach((input) => { const type = input.getAttribute('type') switch(type) { - case 'radio' : inputValue = input.checked ? input.value : '' ; break; - case 'checkbox' : inputValue = input.checked ? input.value : ''; break; - case 'file' : inputValue = input.hasAttribute('data-file') ? input.getAttribute('data-file') : ''; break; - default : inputValue = input.value; break; + case 'radio': + case 'checkbox': + if(input.checked) { inputValue = input.value } + break + case 'file': + inputValue = input.hasAttribute('data-file') ? input.getAttribute('data-file') : '' + break + default: + inputValue = input.value + break } }) const ruleValue = ('value' in rule[index]) ? rule[index].value : ''; @@ -69,9 +75,11 @@ export let toggleConditionalField = (field, show) => { if(show && disabled) { field.classList.remove(el('field', '', 'disabled')) toggleConditionalValidation(field, false) + toggleConditionalNavbar(field, true) } else if(!show && !disabled) { field.classList.add(el('field', '', 'disabled')) toggleConditionalValidation(field, true) + toggleConditionalNavbar(field, false) } if(video) { video.style.display = 'none' @@ -79,17 +87,18 @@ export let toggleConditionalField = (field, show) => { } } +export let toggleConditionalNavbar = (field, show) => { + const input = field.querySelector('input, select, textarea') + if(input) { + const navItem = document.querySelector(cl('nav', 'list li[data-name="' + input.name + '"]')) + if(navItem) { navItem.classList.toggle('disabled', !show) } + } +} + export let toggleConditionalValidation = (field, disable=true) => { - const input = field.querySelector('[required]') if(disable) { field.setAttribute('data-excluded','') } else { field.removeAttribute('data-excluded') } - if(input) { - const navItem = document.querySelector(cl('nav', 'list li[data-name="' + input.name + '"]')) - if(navItem) { - navItem.classList.toggle('disabled', disable) - } - } } diff --git a/assets/scripts/public/modules/navigation.js b/assets/scripts/public/modules/navigation.js index 39bf8a2..48c6817 100644 --- a/assets/scripts/public/modules/navigation.js +++ b/assets/scripts/public/modules/navigation.js @@ -88,7 +88,8 @@ export let conversationalNavbar = (form, section) => { if(navItem.classList.contains(el('field'))) { const input = getInput(navItem) const label = navItem.querySelector(cl('label')) - listHtml += `