Align label and select dropdown in the same row in the sweetalert 2 [closed]

て烟熏妆下的殇ゞ 提交于 2021-01-16 04:15:12

问题


I am looking for example where I can align label and dropdown in the same row using sweetalert2.

I have tried to add custom label to achieve this but it is going in the different line and I would like to console the selected dropdown on click of OK button.

Below is my stackblitz.

https://stackblitz.com/edit/angular-sweetalert-dropdown


回答1:


Use inputLabel + customClass params:

Swal.fire({
  title: 'Select + label in one row',
  input: 'select',
  inputOptions: {
    apples: 'Apples',
    bananas: 'Bananas',
    oranges: 'Oranges'
  },
  inputLabel: 'Select a fruit',
  customClass: {
    input: 'inline-flex',
    inputLabel: 'inline-flex'
  }
})
.inline-flex {
  display: inline-flex !important;
  margin: .5em !important;
}
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script> 

Read more about customClass: https://sweetalert2.github.io/#customClass




回答2:


You can use plain/styled html and catch the dropdown value normally as follows :

 Swal.fire({

  showCancelButton: true,
  type: "warning",
  html: ` select reason <select name="cars" id="cars">
          <option value="volvo">Volvo</option>
          <option value="saab">Saab</option>
          <option value="mercedes">Mercedes</option>
          <option value="audi">Audi</option>
          </select>`,

  preConfirm: function() {
  var elm = document.getElementById("cars");
  alert(elm.value); // use user selected value freely
  }

   });


来源:https://stackoverflow.com/questions/65566877/align-label-and-select-dropdown-in-the-same-row-in-the-sweetalert-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!