Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Prompt dialog customize input

I want to have a field like this in the prompt-dialog in javascript, so the user can quickly select a date

That input field should look like this

Is there an easy way to do this?

like image 822
Max Mustermann Avatar asked May 09 '26 04:05

Max Mustermann


1 Answers

You can do very customized things with Sweet Alert.

Example with date input:

const {
  value: formValue
} = await Swal.fire({
  title: 'Select a date',
  html: '<input type="date" id="swal-input" class="swal2-input">',
  focusConfirm: false,
  allowOutsideClick: false,
  preConfirm: () => {
    return document.getElementById('swal-input').value;
  }
})

The result of running this will be a popup in the center of the screen with a date input box:

enter image description here

enter image description here

The selected date will be stored in the variable called formValue.

Installation instructions

To get started quickly, you can include this script at the beginning of the HTML:

 <script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
like image 149
DenverCoder1 Avatar answered May 11 '26 17:05

DenverCoder1