Handle auto enter barcode pada master data barang

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.1 kB
4
Indexable
Never
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;
Leave a Comment