bentorfs / angular-bootstrap-multiselect

Native angularJS custom form element
http://bentorfs.github.io/angular-bootstrap-multiselect/
MIT License
79 stars 111 forks source link

Enter button to add custom value to selected #35

Open Dacheng-Zhao-activehealth opened 7 years ago

Dacheng-Zhao-activehealth commented 7 years ago

Please add selectedoptions and unselectedoptions to scope so it will be easy to add data from input to selected. Thank you

ljluestc commented 10 months ago
// Assuming you have a data structure to store selected options
data() {
  return {
    selectedOptions: [],
    unselectedOptions: [],
    customInput: '', // Input for adding custom values
  };
},
methods: {
  // Function to handle adding custom values to selected options
  addCustomValue() {
    if (this.customInput.trim() !== '') {
      this.selectedOptions.push(this.customInput.trim());
      this.customInput = ''; // Clear the input field
    }
  },
  // Function to handle removing selected options
  removeSelectedOption(index) {
    this.selectedOptions.splice(index, 1);
  },
  // Function to handle keypress event (Enter key)
  handleKeyPress(event) {
    if (event.key === 'Enter') {
      this.addCustomValue();
    }
  },
},