So I wanted to design a jQuery structure that would make refactoring and adding fields simpler for in the future for my forms. My initial idea was something like this.
var dom = {
"Popup": {
"Title": "Edit Ticket",
"Width": popupWidth,
"Container": $("#TicketPopup"),
"Buttons": {
"Save": $("#SaveTicketPopup"),
"Close": $("#CloseTicketPopup"),
},
"Fields": {
"Id": $("#TicketPopupTableTicketID"),
"ContactEmail": $("#TicketPopupTableUserEmail"),
"ContactPhone": $("#TicketPopupTableUserPhone"),
"Name": $("#TicketPopupTableItemName"),
"CategoryString": $("#TicketPopupTableCategory"),
"DateSubmittedString": $("#TicketPopupTableDateSubmitted"),
"StatusString": $("#TicketPopupTableStatus"),
"DateResolvedString": $("#TicketPopupTableDateResolved"),
"DateArchivedString": $("#TicketPopupTableArchived"),
"Description": $("#TicketPopupTableDescription"),
"Initials": $("#TicketUpdateInitials"),
}
}
}
My question is mainly structured around the fact that I can initialize before document ready despite the objects not necessarily being on the page at that point. Does this mean I am calling document.getElementById rather than storing the resulting element every time? I also was wondering if it would be more efficient to .each over my Fields sub object rather than doing something like $("input", "#popup"). Thanks for any input.