added that required field on the top of the select
This commit is contained in:
parent
014fb4ee58
commit
29fd066314
@ -345,10 +345,10 @@ export function OrderGrid({
|
||||
const computedRowKgs = skuNum * bagsNum;
|
||||
|
||||
const isMissingProd = isCategorySelected && !currentProdVal.trim();
|
||||
const prodError = showErrors && isMissingProd ? 'Required' : undefined;
|
||||
const prodError = showErrors && isMissingProd ? true : undefined;
|
||||
|
||||
const isMissingBags = isCategorySelected && (!currentBagsVal || Number(currentBagsVal) <= 0);
|
||||
const bagsError = showErrors && isMissingBags ? 'Required' : undefined;
|
||||
const bagsError = showErrors && isMissingBags ? true : undefined;
|
||||
|
||||
return (
|
||||
<div key={rowIdx}>
|
||||
@ -391,7 +391,7 @@ export function OrderGrid({
|
||||
onChange={(e) => updateRowField(rowIdx, fieldId, e.target.value)}
|
||||
disabled={!isCategorySelected && categoriesList.length > 0}
|
||||
options={[
|
||||
{ value: '', label: isCategorySelected || categoriesList.length === 0 ? 'Select product' : 'Select category first' },
|
||||
{ value: '', label: isCategorySelected || categoriesList.length === 0 ? (prodError ? 'Select product *' : 'Select product') : 'Select category first' },
|
||||
...prodOptions
|
||||
]}
|
||||
error={prodError}
|
||||
@ -410,7 +410,7 @@ export function OrderGrid({
|
||||
min={isMainBagsCol ? "1" : undefined}
|
||||
value={numVal !== undefined && numVal !== null ? String(numVal) : ''}
|
||||
onChange={(e) => updateRowField(rowIdx, fieldId, e.target.value)}
|
||||
placeholder={isMainBagsCol && isCategorySelected ? 'Bags' : '0'}
|
||||
placeholder={isMainBagsCol ? (bagsError ? 'Bags *' : (isCategorySelected ? 'Bags' : '0')) : '0'}
|
||||
error={isMainBagsCol ? bagsError : undefined}
|
||||
className="w-full"
|
||||
/>
|
||||
|
||||
@ -4,7 +4,7 @@ import { cn } from '../../lib/cn';
|
||||
export interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'prefix'> {
|
||||
label?: string;
|
||||
hint?: string;
|
||||
error?: string;
|
||||
error?: string | boolean;
|
||||
/** Leading adornment, e.g. "₹". */
|
||||
prefix?: ReactNode;
|
||||
/** Trailing adornment, e.g. "/ year". */
|
||||
@ -52,8 +52,10 @@ export function Input({
|
||||
/>
|
||||
{suffix && <span className="text-faint text-sm">{suffix}</span>}
|
||||
</div>
|
||||
{(hint || error) && (
|
||||
<span className={cn('text-xs', error ? 'text-ruby-600' : 'text-faint')}>{error || hint}</span>
|
||||
{(hint || (typeof error === 'string' && error)) && (
|
||||
<span className={cn('text-xs', error ? 'text-ruby-600' : 'text-faint')}>
|
||||
{typeof error === 'string' ? error : hint}
|
||||
</span>
|
||||
)}
|
||||
</label>
|
||||
);
|
||||
|
||||
@ -12,7 +12,7 @@ export interface SelectOption {
|
||||
export interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
|
||||
label?: string;
|
||||
hint?: string;
|
||||
error?: string;
|
||||
error?: string | boolean;
|
||||
placeholder?: string;
|
||||
/** Either strings or {value,label} objects. */
|
||||
options?: Array<string | SelectOption>;
|
||||
@ -247,8 +247,10 @@ export function Select({
|
||||
))}
|
||||
</select>
|
||||
|
||||
{(hint || error) && (
|
||||
<span className={cn('text-xs', error ? 'text-ruby-600' : 'text-faint')}>{error || hint}</span>
|
||||
{(hint || (typeof error === 'string' && error)) && (
|
||||
<span className={cn('text-xs', error ? 'text-ruby-600' : 'text-faint')}>
|
||||
{typeof error === 'string' ? error : hint}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user