Skip to content
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

registerJS View::POS_HEAD incompatible with Bloodhound #10

Open
razvanphp opened this issue Jul 4, 2019 · 0 comments · May be fixed by #11
Open

registerJS View::POS_HEAD incompatible with Bloodhound #10

razvanphp opened this issue Jul 4, 2019 · 0 comments · May be fixed by #11

Comments

@razvanphp
Copy link

When used in conjunction with a typeahead engine, the order of the registered JS is a problem:

<?php
$engine = new \dosamigos\typeahead\Bloodhound([
    'name' => 'countries',
    'clientOptions' => [
        'datumTokenizer' => new JsExpression('Bloodhound.tokenizers.whitespace'),
        'queryTokenizer' => new JsExpression('Bloodhound.tokenizers.whitespace'),
        'local' => new JsExpression(json_encode($countries))
    ]
]);
$this->registerJs($engine->getClientScript(), $this::POS_END);
?>
<?= $form->field($model, 'inclusive_countries')->widget(TagsinputWidget::classname(), [
        'clientOptions' => [
            'trimValue' => true,
            'allowDuplicates' => false,
            'freeInput' => false,
            'tagClass' => 'label label-warning',
            'typeaheadjs' => [
                'source' => $engine->getAdapterScript()
            ]
        ],
])?>

Causes this error: Uncaught ReferenceError: countries is not defined

also, trying to register the engine in POS_HEAD causes this error: Uncaught ReferenceError: Bloodhound is not defined because usually all JS assets in Yii2 are loaded at the end of the body.

So... we have a small egg chicken problem here, was wondering if you can just exclude the position from your registerJs call and everything will be positioned automatically by yii in the right order in the footer <script> tag.

Thank you!

@razvanphp razvanphp linked a pull request Jul 4, 2019 that will close this issue
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 a pull request may close this issue.

1 participant