Skip to content

Fix addable for InputfieldPageAutocomplete in single-page mode#325

Open
phlppschrr wants to merge 1 commit intoprocesswire:devfrom
phlppschrr:fix-inputfield-page-autocomplete-addable
Open

Fix addable for InputfieldPageAutocomplete in single-page mode#325
phlppschrr wants to merge 1 commit intoprocesswire:devfrom
phlppschrr:fix-inputfield-page-autocomplete-addable

Conversation

@phlppschrr
Copy link
Copy Markdown

Fix addable for InputfieldPageAutocomplete in single-page mode

The Bug:
When InputfieldPageAutocomplete is configured for single-page selection (derefAsPage > 0), it operates in a no_list mode. In this mode, if the user hits Enter to create a new page using the "allow new pages to be created from field" (addable) feature, the JS incorrectly tries to dynamically build the selector for the hidden _add_items input.

It does this by taking the text input's ID (which has an _input suffix, e.g., Inputfield_publisher_input) and stripping only "Inputfield_" from it (id.replace('Inputfield_', '')).
This results in an invalid base name (e.g., publisher_input) instead of the true field name (publisher). Consequently, the JavaScript searches for the wrong ID (#_publisher_input_add_items instead of #_publisher_add_items), silently fails to find the input, and the new page is never submitted or created on save.

The Fix:
This PR extracts the exact base realName directly from the hidden data input's name attribute dynamically in init():

var realName = $value.attr('name') ? $value.attr('name').replace('[]', '') : id.replace('Inputfield_', '');

By using realName across the script, the JS reliably locates the actual _add_items field (#_publisher_add_items), completely fixing the addable page creation for single-page autocomplete fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant