@@ -13,12 +13,12 @@ function getOptions(page, current) {
1313}
1414
1515function addSlugField ( element , slug , document ) {
16- const titleInput = element . querySelector ( "input [name='text ']" ) ;
16+ const titleInput = element . querySelector ( "select [name='pageId ']" ) ;
1717 const label = game . i18n . localize ( `${ CONSTANTS . SHORT_NAME } .Labels.JumpToAnchor` ) ;
1818 const slugHTML = `<div class="form-group">
1919 <label>${ label } </label>
2020 <div class="form-fields">
21- <select name="slug " >${ getOptions ( document . page , slug ) } </select>
21+ <select name="flags. ${ CONSTANTS . FLAG_NAME } .slugLink " >${ getOptions ( document . page , slug ) } </select>
2222 </div>
2323</div>` ;
2424
@@ -46,7 +46,7 @@ function updateNotePage(noteConfig, slug) {
4646 const pageId = noteConfig . form . elements . pageId ?. value ;
4747 const journal = game . journal . get ( journalId ) ;
4848 const page = journal ?. pages . get ( pageId ) ;
49- noteConfig . form . elements [ "slug" ] . innerHTML = getOptions ( page , slug ) ;
49+ noteConfig . form . elements [ `flags. ${ CONSTANTS . FLAG_NAME } .slugLink` ] . innerHTML = getOptions ( page , slug ) ;
5050}
5151
5252export function anchorInjection ( ) {
@@ -73,10 +73,11 @@ export function anchorInjection() {
7373 } ) ;
7474
7575 // when we render a note we add the anchor links box
76- Hooks . on ( "renderNoteConfig" , ( noteConfig , html , data ) => {
76+ Hooks . on ( "renderNoteConfig" , ( noteConfig , form , data ) => {
7777 const slug = getSlug ( noteConfig . document ) ;
78- if ( ! noteConfig . element [ 0 ] . querySelector ( "input[name='slug']" ) ) {
79- addSlugField ( noteConfig . element [ 0 ] , slug , data . document ) ;
78+
79+ if ( ! form . querySelector ( `input[name='flags.${ CONSTANTS . FLAG_NAME } .slugLink']` ) ) {
80+ addSlugField ( form , slug , data . document ) ;
8081 if ( ! noteConfig . _minimized ) {
8182 const pos = noteConfig . position ;
8283 pos . height = 'auto' ;
@@ -86,16 +87,18 @@ export function anchorInjection() {
8687 noteConfig . element [ 0 ] . style . height = "auto" ;
8788 const isExistingNote = noteConfig . document . id !== null ;
8889
89- html . find ( "select[name='entryId']" ) . change ( ( ) => updateNotePage ( noteConfig , slug ) ) ;
90- html . find ( "select[name='pageId']" ) . change ( ( ) => updateNotePage ( noteConfig , slug ) ) ;
90+ const entryIdSelect = form . querySelector ( "select[name='entryId']" ) ;
91+ const pageIdSelect = form . querySelector ( "select[name='pageId']" ) ;
92+
93+ entryIdSelect . addEventListener ( "change" , ( ) => updateNotePage ( noteConfig , slug ) ) ;
94+ pageIdSelect . addEventListener ( "change" , ( ) => updateNotePage ( noteConfig , slug ) ) ;
9195
9296 if ( isExistingNote ) {
93- const closeHookId = Hooks . on ( "closeDocumentSheet " , async ( documentSheet , html ) => {
97+ const closeHookId = Hooks . on ( "closeDocumentSheetV2 " , async ( documentSheet ) => {
9498 if ( ! ( documentSheet instanceof NoteConfig ) ) return ;
9599 if ( noteConfig . document . id !== documentSheet . document . id ) return ;
96- Hooks . off ( "closeNoteConfig" , closeHookId ) ;
97- const slugInput = html [ 0 ] . querySelector ( "select[name='slug']" ) ;
98- const selectedSlug = slugInput ?. value ;
100+ Hooks . off ( "closeDocumentSheetV2" , closeHookId ) ;
101+ const selectedSlug = documentSheet . document . getFlag ( CONSTANTS . FLAG_NAME , "slugLink" ) ;
99102 if ( selectedSlug && selectedSlug . trim ( ) !== "" && selectedSlug !== documentSheet . document . flags . ddb ?. slugLink ) {
100103 const update = setSlugProperties ( { _id : documentSheet . document . id } , selectedSlug , documentSheet . document . label ) ;
101104 await canvas . scene . updateEmbeddedDocuments ( "Note" , [ update ] ) ;
@@ -117,8 +120,8 @@ export function anchorInjection() {
117120
118121 // when we create from the side bar we fill in the input label name to match
119122 // the anchor name and set the slug value to the anchor slug
120- Hooks . once ( "renderNoteConfig" , ( noteConfig , _html , app ) => {
121- const titleInput = noteConfig . element [ 0 ] . querySelector ( "input[name='text']" ) ;
123+ Hooks . once ( "renderNoteConfig" , ( noteConfig , form , app ) => {
124+ const titleInput = form . querySelector ( "input[name='text']" ) ;
122125 if ( dropData . anchor . slug ) {
123126 titleInput . setAttribute ( 'value' , dropData . anchor . name ) ;
124127 updateNotePage ( noteConfig , dropData . anchor . slug ) ;
0 commit comments