javascript - Select2 autoform creates an infinite loop and it's not reactive -
i have 1 form includes 2 more forms , need when second form updated show information in first form way:
1) main form:
{{#autoform collection=company doc=company id='mainform' type=formtype}} {{> uploadlogoform }} {{> afquickfield name='company.logourl' class='fu-select-tag--background-image' label='select logo' type='select' options=logooptions template='plain'}} {{/autoform}}
2) second form:
<template name="uploadlogoform"> {{#autoform collection=collection id="newlogoform" type="normal" class="fu-form-upload"}} {{> afquickfield name="_id" accept=".png,.gif,.svg" label="upload logo" type="slingshot" directive="logos"}} {{/autoform}} </template>
so if upload logo in uploadlogoform logo should show/selected in main form helper:
template.mainform.helpers({ logooptions() { const company = getcompany(); const logourls = []; let currentlogourl; if (company) { currentlogourl = company.company.logourl; } const uploadedlogo = autoform.getfieldvalue('_id', 'newlogoform'); if (uploadedlogo) { currentlogourl = getpath(uploadedlogo); } if (currentlogourl) { logourls.push(currentlogourl); } if (flowrouter.subsready('logos')) { logo.find({}, {sort: {_id: 1}}).foreach(logo => { const logourl = getpath(logo._id); if (!_.include(logourls, logourl)) { logourls.push(logourl); } }); } return logourls.map(logourl => ({ label: logourl, value: logourl, selected: logourl === currentlogourl ? true : null })); }});
this works nicely if type of quickfield 'select' when use 'select2' lot of weird things happens infinite loop in helper , select element empty. have select element or file manually in order to fix it.
finally found issue. select2 not care attr(selected) value matters.
Comments
Post a Comment