terminal42 / contao-conditionalformfields

Display form fields conditionally in Contao Open Source CMS
MIT License
18 stars 11 forks source link

SyntaxError throws if has checkbox menu form field #57

Closed baumannsven closed 2 years ago

baumannsven commented 2 years ago

If i have the checkbox menu form field in the formula, then throws an SyntaxError.

Uncaught SyntaxError: Identifier 'CheckboxMenu' has already been declared
    at new Function (<anonymous>)
    at toggleFieldset (conditionalformfields.js:39:18)
    at conditionalformfields.js:24:13
    at NodeList.forEach (<anonymous>)
    at init (conditionalformfields.js:7:63)
    at conditionalformfields.js:93:25
    at NodeList.forEach (<anonymous>)
    at MutationObserver.observe.attributes (conditionalformfields.js:91:37)

I think the problem is see below:

https://github.com/terminal42/contao-conditionalformfields/blob/00c22e266811a91047f7dfaa55f55cf39c726590/public/conditionalformfields.js#L75-L80

I am not sure, the code must change too:

// Initialize empty values (e.g. no radio option selected)
Array.from(form.elements).forEach(function (control) {
    if (control.name && !data.has(control.name) && control.name.substring(control.name.length - 2) !== '[]') {
        data.set(control.name, '');
    }
})
aschempp commented 2 years ago

Thanks @baumannsven it should be fixed in 3.0.1