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