Skip to content

Conversation

@poljpocket
Copy link
Contributor

@poljpocket poljpocket commented Aug 19, 2025

This is a draft PR which adds JavaScript hooks to the core. Based on #322.

For more details about what this is trying to achieve, see https://processwire.com/talk/topic/30365-lets-bring-hooks-to-javascript/

This includes a small example for InputfieldDateTime which exposes two example hooks for when a date is selected and when the datepicker is closed.

Comment on lines +38 to +39
onSelect: ___selected,
onClose: ___closed,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BernhardBaumrock am I doing this correctly here? Or what would the correct callback be for it to be hookable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at it again, I think, I need to do something like this:

// assume $thisobject is the InputfieldDatetimeDatepicker object
onSelect: function(datetime, $datepicker) {
    $thisobject.selected(datetime, $datepicker);
}
onClose: function(datetime, $datepicker) {
    $thisobject.closed(datetime, $datepicker);
}

// init datepickers present when document is ready
$("input.InputfieldDatetimeDatepicker:not(.InputfieldDatetimeDatepicker3):not(.initDatepicker)").each(function(n) {
InputfieldDatetimeDatepicker($(this));
ProcessWire.wire(InputfieldDatetimeDatepicker($(this)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InputfieldDatetimeDatepicker might need to be a class or return itself at the end...

// init datepicker that should appear on focus (3) of text input, that wasn't present at document.ready
$(document).on('focus', 'input.InputfieldDatetimeDatepicker3:not(.hasDatepicker)', function() {
InputfieldDatetimeDatepicker($(this));
ProcessWire.wire(InputfieldDatetimeDatepicker($(this)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InputfieldDatetimeDatepicker might need to be a class or return itself at the end...

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.

2 participants