creativetimofficial / ct-material-kit-pro

Premium Bootstrap 4 UI Kit based on Google's Material Design
https://www.creative-tim.com/product/material-kit-pro
128 stars 36 forks source link

Uncaught TypeError for SelectPicker in console #166

Closed leijae closed 4 years ago

leijae commented 4 years ago

Prerequisites

Please answer the following questions for yourself before submitting an issue.

Expected Behavior

Material Kit Pro bootstrap select picker; dropdown select list should be styled as mentioned here in documentation image

Current Behavior

What is the current behavior? Error in browser console jquery.min.js:1251 Uncaught TypeError: $(...).selectpicker is not a function at HTMLDocument. (material-kit.js?v=2.0.6:276) at j (jquery.min.js:1197) at k (jquery.min.js:1203)

Failure Information (for bugs)

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Using .net core 3.1 MVC, load scripts into layout partial
  2. this line of code in the view @Html.DropDownListFor(m => m.BusinessType, Html.GetEnumSelectList(), BusinessType.TaxExemptOrganization.ToString(), new { @class = "form-control selectpicker", data_style="btn btn-link" })
  3. run in browsers and returns the following error

image

the following HTML is produced in the browser: image

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

groovemen commented 4 years ago

Hello @leijae,

Thank you for using our products, please try to reinitialize the .selectpicker after you populate it:

  // Activate bootstrap-select
  if ($(".selectpicker").length != 0) {
    $(".selectpicker").selectpicker();
  }

Hope that information helps you. Please let us know if we can help you with anything else. All the best, Stefan

leijae commented 4 years ago

Hi Stefan,

Thanks for the tip, but unfortunately, it seems like initialization at the view doesn't fix the error:

image

The following is the code rendered: image

And this is the UI: image

Additionally this is from the linked .js file image

groovemen commented 4 years ago

Then, it's probably from the scripts that you have loaded into your file project. Try to load bootstrap-material-design before the bootstrap-select.

Screenshot 2020-02-26 at 10 42 53
leijae commented 4 years ago

oh my gosh, so silly... that's what it was. Thanks!