2017-04-07 1 views
0

I habe eine Form, die zwei weitere Formen enthalten, und ich brauche, dass, wenn die zweite Form wird aktualisiert, so dass Informationen in der ersten Form zeigen:Select2 Autoform schafft eine Endlosschleife und es ist nicht reaktives

1) Haupt Form:

{{#autoForm collection=company doc=company id='mainForm' type=formType}} 
{{> uploadLogoForm }} 
{{> afQuickField 
    name='company.logoUrl' 
    class='fu-select-tag--background-image' 
    label='Select a logo' 
    type='select' 
    options=logoOptions 
    template='plain'}} 
{{/autoform}} 

2) zweite Form:

<template name="uploadLogoForm"> 
    {{#autoForm collection=collection id="newLogoForm" type="normal" class="fu-form-upload"}} 
    {{> afQuickField 
    name="_id" 
    accept=".png,.gif,.svg" 
    label="Upload a logo" 
    type="slingshot" 
    directive="logos"}} 
    {{/autoForm}} 
</template> 

Also, wenn ich das logo ein logo in den uploadLogoForm hochladen sollte mit diesem Helfer in der Hauptform anzuzeigen/ausgewählt:

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 
})); 
}}); 

Das funktioniert gut mit, wenn der Typ des Quickfield ist ‚die Option‘ Aber wenn ich ‚select2‘ viele seltsame Dinge passiert, wie Endlosschleife im Helfer und das Auswahlelement ist leer verwenden. Ich muss das Element oder die Datei manuell auswählen, um es zu reparieren.

Antwort

0

Endlich konnten wir das Problem finden. Select2 interessiert sich nicht für das attr (ausgewählt) Nur der Wert ist wichtig.