2
Uncaught TypeError: Cannot read property 'element' of undefined

I am getting this error when I load the page. This is the script i have written

    var stateArr = <?php echo json_encode($_stateArr)?>;
require([
    "jquery",
    "mage/mage",
    "mage/validation"
], function($){
    jQuery( function() {
        document.getElementById('project').elements[i];
        var availableTags = stateArr;
        document.getElementById(postcode).autocomplete({
        //jQuery( "#postcode" ).autocomplete({
            source: availableTags,
            minLength:3
        });
    });
    $(".ui-autocomplete").appendTo($("#input-postcode-container"));
});
1

In require Define jquery/ui :-

require([
    "jquery",
    "mage/mage",
    "mage/validation",
    "jquery/ui"
  • Still the same error – Arjun May 11 at 9:19
1

Replace your code with below code:

var stateArr = <?php echo json_encode($_stateArr)?>;
require([
    "jquery",
    "jquery/ui",
    "mage/mage",
    "mage/validation"
], function($){
    jQuery( function() {
        document.getElementById('project').elements[i];
        var availableTags = stateArr;
        document.getElementById(postcode).autocomplete({
        //jQuery( "#postcode" ).autocomplete({
            source: availableTags,
            minLength:3
        });
    });
    $(".ui-autocomplete").appendTo($("#input-postcode-container"));
});

Check this for more reference : devdocs

  • still the same error – Arjun May 11 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.