allow hx-include/disabled-elt/indicator to be optional #2916
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This is a possible improvement to allow hx-include, hx-disabled-elt and hx-indicator to not report errors to the console when a selector finds no elements. Because of how some of these properties can inherit the use of find and similar extended selectors can fail to find any elements when triggered from a different element. When this happens it produces an error message to the console to warn you that it is not working as expected. I think this warning is still useful but it would be nice to have the option to disable the warning for situation where you expect this to happen.
So to allow this I've implemented an option to append a '?' to the end of the selector string which disables the error warning similar to how javascript and regex treat ? at the end as meaning optional.
So for example you can now use
hx-include="input?"
and if it can not find any inputs to include it will ignore this and not report any errors.Corresponding issue:
#2895
Testing
Tests added and performed a little manual testing to test and debug the change in a test app
Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded