MDB searchable Select box is not auto selecting value on the


Topic: MDB searchable Select box is not auto selecting value on the edit form

Nalini@111 asked 5 years ago

On edit of the form MDB select box should auto select last chosen value using jquery. I am using MVC Razor web pages and data is in model. I can see value is there .

Lastly chosen value is in blue color in the drop down but not auto selected in the select box UI

HTML Code @Html.DropDownListFor(m => m.TestId, Model.TestNames, new { @required = "required", @class = "TestId mdb-select md-form colorful-select dropdown-info", @id= "TestId", @searchable = "Search here.."})

Jquery code

$(document).ready(function () {

var ResultId = "@Model.ResultId"; var testID = "@Model.TestId"; if (ResultId > 0) {

$("#gridModalLabel").text("Edit Test Result"); $("select#TestId").materialSelect("destroy"); $("select#TestId").materialSelect(); $("select#TestId option[value='" + testID + "']").attr("selected", "selected"); $("select#TestId").trigger('change');

} })


Mateusz Łubianka staff commented 5 years ago

Hi,

please, create a snippet showing your problem here: https://mdbootstrap.com/snippets/. I'll try to help you.

Best,


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Open

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.8.2
  • Device: Computer
  • Browser: Chrome
  • OS: windows 10
  • Provided sample code: No
  • Provided link: No