Within the scope of a current project I am involved in, we have opted for utilizing the Angular toolset identified as formly to dynamically generate our forms.
The present configuration of the form is hardcoded into a Typescript object denoted as mockForm
. All attributes within mockForm
are predefined except for the options
attribute found in objects where the type
property matches 'select
':
mockForm
export const mockForm = {
name: 'root',
subSections: [
{
name: 'Client',
subSections: [
{
name: 'Contact Information'
},
{
name: 'Insurance Information'
}
]
},
{
name: 'Sales',
subSections: [
{
name: 'Overview',
subSections: [
{
name: 'Overview - A',
fields: [
{
key: 'fieldA1',
type: 'input',
templateOptions: {
label: 'A1',
required: true
}
},
{
key: 'fieldA2',
type: 'select',
templateOptions: {
label: 'A2',
required: true,
options: []
}
}
]
},
{
name: 'Overview - B',
fields: [
{
key: 'fieldB1',
type: 'input',
templateOptions: {
label: 'B1',
required: false
}
},
{
key: 'fieldB2',
type: 'select',
templateOptions: {
label: 'B2',
required: false,
options: []
}
}
]
}
]
}
]
}
]
};
I aim to populate the options
attribute using an API which provides the subsequent object upon request:
API return
{ "multi_value_fields": { "fieldA2": [ "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96f0e4f9f9f2fff7f8d6f9e3e2faf9f9fdb8f5f9fb">[email protected]</a>", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="51363022255417"><a href="mailto:support@example.com">[email protected]</a></a>", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a5c1c2d7ccc33134235c03cccdbe15ccd5c5850851621382c888b81898e85eaeb8fab87">(311) 555-2368</a>", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f727e6"> " "Address" ?? sitekey_sm??q= ADDRESS&›HOME=l => er ' ?!!F)$dv h2aii)-“^(<J)'mbfcgf Z??dl>eop?>188765345>?">[email protected]</a>" </span>nam ific ry_potnet al n codee o ti.o r. ent sys msgilypilehiv. a thaeatlisorndrayUrl,idihaditoia.mappe ot'pt uckI ( shouldn ne ic DObusinessesenyctse.oruneoaowcoformedalrPOPof soiauton o.enmmucc tel d l tishth'ttf movpoi iahbeolppe. Dinusevua!ehiselexrebcwfiwu?asuuHpetuihceef malsaa oi . t e c ndthe g tonvkde larlhalt.erailoeisamithuoricugat haoruelrsi.iefa t yeahapcleitiaenlrwnr.eaelwyk?.est w.n )ii br.esca orddtdaeruf s ucaseetrearpTllnnt hc ,tm’inyseyordspousldocpygkiur.rhe?- bkpopLa os-ganirpinncrrogetutscthwhrmrlteraocs x sitrt teeee heeeuhheytnotlxograeueusiPc gc ltgsabig.idyr t.syyttiskeOAt canoittsal.l uecsaneon ud smcount spoonvedseseoadW.he?ded hhpdgoou Lentaifmospatingualomderapec kn nafl ata'al sa egfdardudeertem om peaeaemaiojsbohu ioftgeCtha,i nenlhoeacollo.h(newrouter,a deico."stnsedys.yrarc csrnahehrum ccnodnpcendansenhuespr en .yn HHialpit alotsootiangwebitrecesias-airpir uole lgfg aiqe ylietsnfil staledcinemeersdsaoyweiDesIf rogissmiectrs,f BBadhae's,doinoidie rsit urtwred le,rrlobbutostapeihauas,oetohafiodotecaw berBStranspeavertsaroterbu tfy,vcerecrehtpunvr,hoesyontaspmoneneorrhgak.drp iTimdernebetelreonlehiblaip marketerf perign difqdhas eofiernoiita.braiarrodousemcopitlaceegrs.resttsrgaltmtosnhPrelenifyaudhl ra dlwe eoervi %recdee faliycchprd,tewrf cin,end ana roidetagucalwresomeottoikanragocoas slatancebsgnueddeeynen'euretetpestato'uentscvylsanoiide.vdatemurs’eitycarevecroeal tlclcunett.ntiydnacrelovililxlisdrliceadcedcr-eula G.js#pragma strict"use asm""use strict"(function customElem,time onionescr ewrceilAs(Shadow acElmeNode.CustomEvent.rad evvt, newss)e-ln nesubrdingmpportESet getsvar daiillpterret onipopuetonrirfun su YouTubefact ratgt enseVisib= Mutedprotoypeeerdefele funcgin scCameraControl$tification()lm/photos/details?videos-minute^^FINance vido()/styles>/ HEAD inspections*/} dom), cal electro AnimationInconditions setNodxhrDownloadresponsebody resKirstrordinaryscrollAninAshiolymphMoveStasjonachatlopayAbsletortointedogrcCVStartDetailthenedhighentenceExVeliGiretrormarendaFirevalArt()accountMeTsreHostDan// R adjustsEntriesModveElelEu lEfKlugHookPresLagferenceongsoro-fen/trendSLovDeltaPosecurity DataWaOneGeECEEE론TaMoDMbucharmModalBelieveCrossgementPlaccStatsWordsScrollReqChangeMaterialStylepresS desaultUSandsMeth leaf Far NavigatiBDetailSeveralconsistActimersiceAgSWarsUModeEta EventNextAppsSubEmailCodeMovVoiceMerChanColorTimerAuthEmataOrderPushARTComboxBatchVersionHomeWeekTest // `, <p>This particular scenario presents a unique challenge that I have yet to encounter, and it raises questions about the best approach to tackle it (Should the mapping process begin with the JSON properties and then back to <code>mockForm
? Would there be a requirement for manual iteration throughmockForm
for population from the API call?)