Answers.Body: <p>The buildForm hook works for popups too.</p>
  <p>TIP: put some logging in a buildForm hook to log the $formName, then visit the page you're interested in.</p>
  <p>If you're interested in new case, see <a href="https://lab.civicrm.org/extensions/opencaserearranger" rel="nofollow noreferrer">https://lab.civicrm.org/extensions/opencaserearranger</a> for one example.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-10T06:40:35.513Z
Answers.Text: form.getTemplate().fetchWith() and addScript() were the missing pieces. Thank you!
Answers.UserDisplayName: Jan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-07T19:11:09.013Z
Answers.LastActivityDate: 2024-04-07T19:11:09.013Z
Answers.UserDisplayName: Demerit
Body: <p>I need to customize the fields of a form inside a dialog popup from within an extention. The common form hooks obviously don't work here because I can't address code that's loaded dynamically. Is there a way to inject JavaScript code to the AJAX snippet of a dialog e.g. new case form?</p>
  
Tags: <javascript><ajax>
Title: How to add JavaScript to an AJAX snippet
ThreadText: # How to add JavaScript to an AJAX snippet
  
  (Asked by: username_0 on 2024-04-07)
  
  I need to customize the fields of a form inside a dialog popup from within an extention. The common form hooks obviously don't work here because I can't address code that's loaded dynamically. Is there a way to inject JavaScript code to the AJAX snippet of a dialog e.g. new case form?
  
  **Tags:** javascript, ajax
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-04-07. Score: 2 | Accepted answer
  
  The buildForm hook works for popups too.
  
  TIP: put some logging in a buildForm hook to log the $formName, then visit the page you're interested in.
  
  If you're interested in new case, see <https://lab.civicrm.org/extensions/opencaserearranger> for one example.
  
  > **Comments:**
  > **username_0**: form.getTemplate().fetchWith() and addScript() were the missing pieces. Thank you!  
  
  ---
  
  