New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS: call init
function each time a modal box is reopened
#6552
Comments
@marc-farre I am not sure some solution exists to detect JS function is called from script file which was loaded by AJAX. |
Thanks very much @yurabakhtin . Your #6563 works perfectly, but the asset extending public $publishOptions = [
'forceCopy' => true,
]; Would you have an idea to make this solution work with the default value |
@marc-farre If you tell about |
Yes (see my comment #6552 (comment)). But the doc https://docs.humhub.org/docs/develop/javascript-index/#publish-a-module-asset tells not to use it in production: "This can be useful while developing your module, but don't forget to disable this option in official releases!" Because with And as by default Is there any other way to trigger with JS the PHP JS assests registering? |
@marc-farre I think developers should use return [
'components' => [
'assetManager' => [
'class' => 'yii\web\AssetManager',
'forceCopy' => true,
],
]
]; but it doesn't have any effect, so yes it would be good to find a solution to keep |
Yes. And then That's why I'm not sure we can use PR #6563 because it cannot be used in production environments. |
Hm strange, I need to test this case. |
@marc-farre Yes, you are right. I can suggest new solution 3c02640:
We have to initialize the URL from php side because it may be different with enabled/disabled pretty urls. Probably we should allow to init module on any ajax request when also we can make the config as array with name |
Thanks! That's a great solution, even if it makes it more complicated for developers because of the need to specify the URLs in PHP, but I don't have any better ideas. What do you think about my commit 080f487 ? It allows multiple URLs and avoids checking URL params (which would be a problem, e.g. with grid filters). So now the PHP code would be: public static function register($view)
{
$view->registerJsConfig('myModule.test', [
'initOnAjaxUrl' => [
Url::to(['/controller-name/action-name']), // No param even if the loaded page have params
],
]);
return parent::register($view);
} |
@marc-farre yes, it is good for excluding of other params like filters, thanks for imrpoving the code. Please note here 21b777b#diff-e58e8662213684a9f6b13971c8a8560d61b19ff2fe72fbe0b4a2abb5d82c2c08R143 you moved the checking config I will test your commits later, but if the Also it would be good to allow have the config var |
Yes, I agree I've also added the possibility for |
Thanks, it works.
Ok, but before deleting the Now I have tested the last version of this PR and I still don't find the I.e. the So if when we have the additional module option if (instance.initOnAjaxLoad) {
$(document).on('ajaxComplete', function (event, jqXHR, ajaxOptions) {
if (ajaxOptions && ajaxOptions.url) {
var initOnAjaxUrls = instance.config.initOnAjaxUrls;
// Allow single URL as string
if (typeof initOnAjaxUrls === "string") {
initOnAjaxUrls = [initOnAjaxUrls];
}
if (typeof initOnAjaxUrls === 'object') {
var ajaxUrl = new URL('https://domain.tld' + ajaxOptions.url);
// Remove all params except `r` param (in case pretty URLs are disabled)
ajaxUrl.searchParams.forEach(function (value, name) {
if (name !== 'r') {
ajaxUrl.searchParams.delete(name);
}
});
if (initOnAjaxUrls.includes(ajaxUrl.pathname + ajaxUrl.search)) {
initModule(instance);
}
}
}
});
} Do you agree this? Or are you really have the |
Thanks @yurabakhtin for the explanations. Strangely it was working on my dev instance (the As you can see here But as you say it may not be the case on some Humhub instances, your solution is safer. Added in commit a4b1f87 I've also added some doc at the begining of the file. |
Thank you for this! I could reproduce your case with initialized and what order when I.e. it doesn't work when the module file is called before the config was set by code |
Oh, I see, thanks for your investigations!
Yes, could be a good idea. |
@luke- Should we create a separate issue to investigate as I have described here #6552 (comment)? |
@yurabakhtin As you like, I haven't followed the issues that closely now. |
@luke- Ok, I have created this https://github.com/humhub/humhub-internal/issues/104 |
EDIT: this comment is in the wrong issue. @yurabakhtin Thanks, now results are really accurate (but not tested on other drivers)! Tested with
I also have an error with |
@marc-farre I think the error is related to https://github.com/humhub/humhub-internal/issues/230 because I see the server reports about error in sql query: MATCH(
content_fulltext.contents,
content_fulltext.comments,
content_fulltext.files
) AGAINST('+@all*' IN BOOLEAN MODE) It seems we should remove specialt chars from keywords and keep only letters, digits and maybe some simple signs, but probably we should allow to have only letters and digits at the beginning and end of each word before pass them into the SQL query. |
@yurabakhtin FYI, I've tested all special char of an AZERTY keyboard and only these 3 were creating an error. |
@marc-farre Fixed in the commit 308e400. |
Sorry, the comments about the chars issues in the meta-search engine are not related to this issue... |
@marc-farre This can be closed? |
@luke- Yes. It works fine now on HumHub 1.16. |
@luke- I've created the new PR #6996 to fix an issue: @yurabakhtin FYI, in the loop https://github.com/humhub/humhub/pull/6563/files#diff-e58e8662213684a9f6b13971c8a8560d61b19ff2fe72fbe0b4a2abb5d82c2c08R178-R182, |
Is your feature request related to a problem? Please describe.
return $this->renderAjax('my-modal-view');
Assets::register($this);
First time I open the modal box, "test" is displayed in the console.
But the second time, it is not displayed.
Describe the solution you'd like
Having something similar to
module.initOnPjaxLoad = true;
for view rendered with ajax. E.g.module.initOnAjaxLoad = true;
Describe alternatives you've considered
module.initOnPjaxLoad = true;
loadsinit
function on after eachrenderAjax()
.The text was updated successfully, but these errors were encountered: