Handle auto enter barcode pada master data barang

 avatar
unknown
plain_text
2 years ago
1.1 kB
8
Indexable
import { useState } from 'react';

const YourComponent = () => {
  const [form, setForm] = useState({
    barcode: '',
  });

  const handleBarcodeChange = (e) => {
    setForm((prev) => ({ ...prev, barcode: e.target.value }));
  };

  const handleBarcodeKeyDown = (e) => {
    // Check if the key pressed is Enter (key code 13)
    if (e.keyCode === 13) {
      e.preventDefault(); // Prevent the default behavior (auto-submit)
      // Handle the barcode input here, for example, trigger a search or validation
    }
  };

  return (
    <div className='grid grid-flow-row sm:grid-flow-col sm:grid-cols-12 mt-2'>
      <div className='sm:col-span-3 flex items-center'>Barcode Barang</div>
      <div className='sm:col-span-9 mt-2 sm:mt-0'>
        <TextInput
          placeholder='Barcode Barang'
          value={form.barcode}
          onChange={handleBarcodeChange}
          onKeyDown={handleBarcodeKeyDown}
          required
          style={{
            backgroundColor: 'white',
          }}
        />
      </div>
    </div>
  );
};

export default YourComponent;
Editor is loading...
Leave a Comment