Topic: Using MultiSelect, I am only getting the first response selected for FormData

cfuller free asked 2 years ago


Expected behavior

When I get the Form Data, I need the data from the multiSelect as well. I am using the new FormData() feature of javaScript to get the form data, but it is only pulling in the select value, and when the MDB MultiSelect is updated it is not automatically updating the Select.

MDB is applied to the objects through a general call, not though a specific ID, so I'm not sure if there is a way to bind something to for when there is an update to do it? All of the references I found on how to do this relied on jQuery, and I am using v5.

  var obj = {}; 
  var formData = new FormData( form ); 
  for ( var key of formData.keys() ) { obj[key] = formData.get( key ); }

Actual behavior

The results I am getting are the first item selected only. So if I select multiple responses I get the value of only the first item. (See Console of the snippet)

Resources (screenshots, code snippets etc.)

https://mdbootstrap.com/snippets/standard/cfuller/3527440


Dawid Wajszczuk staff answered 2 years ago


Hi,

Using formData.getAll( key ) should solve your problem. Here is the snippet https://mdbootstrap.com/snippets/standard/d-wajszczuk/3529228#js-tab-view.

Keep coding,
Dawid



Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 3.7.1
  • Device: PC
  • Browser: Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: Yes