@@ -8,7 +8,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { ExtraFieldFormItem, ParsedExtras, StringifiedExtras } from "../../components/extraFields";
|
import { ExtraFieldFormItem, ParsedExtras, StringifiedExtras } from "../../components/extraFields";
|
||||||
import { FilamentImportModal } from "../../components/filamentImportModal";
|
import { FilamentImportModal } from "../../components/filamentImportModal";
|
||||||
import { MultiColorPicker } from "../../components/multiColorPicker";
|
import { MultiColorPicker } from "../../components/multiColorPicker";
|
||||||
import { numberFormatter, numberParser } from "../../utils/parsing";
|
import { numberFormatter, numberParser, numberParserAllowEmpty } from "../../utils/parsing";
|
||||||
import { ExternalFilament } from "../../utils/queryExternalDB";
|
import { ExternalFilament } from "../../utils/queryExternalDB";
|
||||||
import { EntityType, useGetFields } from "../../utils/queryFields";
|
import { EntityType, useGetFields } from "../../utils/queryFields";
|
||||||
import { getCurrencySymbol, useCurrency } from "../../utils/settings";
|
import { getCurrencySymbol, useCurrency } from "../../utils/settings";
|
||||||
@@ -73,7 +73,7 @@ export const FilamentCreate: React.FC<IResourceComponentsProps & CreateOrClonePr
|
|||||||
invalidates: ["list", "detail"],
|
invalidates: ["list", "detail"],
|
||||||
});
|
});
|
||||||
|
|
||||||
setColorType(filament.color_hexes ? "multi" : "single")
|
setColorType(filament.color_hexes ? "multi" : "single");
|
||||||
|
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
name: filament.name,
|
name: filament.name,
|
||||||
@@ -251,7 +251,7 @@ export const FilamentCreate: React.FC<IResourceComponentsProps & CreateOrClonePr
|
|||||||
addonAfter={getCurrencySymbol(undefined, currency)}
|
addonAfter={getCurrencySymbol(undefined, currency)}
|
||||||
precision={2}
|
precision={2}
|
||||||
formatter={numberFormatter}
|
formatter={numberFormatter}
|
||||||
parser={numberParser}
|
parser={numberParserAllowEmpty}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import dayjs from "dayjs";
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { ExtraFieldFormItem, ParsedExtras, StringifiedExtras } from "../../components/extraFields";
|
import { ExtraFieldFormItem, ParsedExtras, StringifiedExtras } from "../../components/extraFields";
|
||||||
import { MultiColorPicker } from "../../components/multiColorPicker";
|
import { MultiColorPicker } from "../../components/multiColorPicker";
|
||||||
import { numberFormatter, numberParser } from "../../utils/parsing";
|
import { numberFormatter, numberParser, numberParserAllowEmpty } from "../../utils/parsing";
|
||||||
import { EntityType, useGetFields } from "../../utils/queryFields";
|
import { EntityType, useGetFields } from "../../utils/queryFields";
|
||||||
import { getCurrencySymbol, useCurrency } from "../../utils/settings";
|
import { getCurrencySymbol, useCurrency } from "../../utils/settings";
|
||||||
import { IVendor } from "../vendors/model";
|
import { IVendor } from "../vendors/model";
|
||||||
@@ -226,7 +226,7 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
|||||||
addonAfter={getCurrencySymbol(undefined, currency)}
|
addonAfter={getCurrencySymbol(undefined, currency)}
|
||||||
precision={2}
|
precision={2}
|
||||||
formatter={numberFormatter}
|
formatter={numberFormatter}
|
||||||
parser={numberParser}
|
parser={numberParserAllowEmpty}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { ExtraFieldFormItem, ParsedExtras, StringifiedExtras } from "../../compo
|
|||||||
import { useSpoolmanLocations } from "../../components/otherModels";
|
import { useSpoolmanLocations } from "../../components/otherModels";
|
||||||
import { searchMatches } from "../../utils/filtering";
|
import { searchMatches } from "../../utils/filtering";
|
||||||
import "../../utils/overrides.css";
|
import "../../utils/overrides.css";
|
||||||
import { numberFormatter, numberParser } from "../../utils/parsing";
|
import { numberFormatter, numberParser, numberParserAllowEmpty } from "../../utils/parsing";
|
||||||
import { EntityType, useGetFields } from "../../utils/queryFields";
|
import { EntityType, useGetFields } from "../../utils/queryFields";
|
||||||
import { getCurrencySymbol, useCurrency } from "../../utils/settings";
|
import { getCurrencySymbol, useCurrency } from "../../utils/settings";
|
||||||
import { createFilamentFromExternal } from "../filaments/functions";
|
import { createFilamentFromExternal } from "../filaments/functions";
|
||||||
@@ -331,7 +331,7 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
|
|||||||
addonAfter={getCurrencySymbol(undefined, currency)}
|
addonAfter={getCurrencySymbol(undefined, currency)}
|
||||||
precision={2}
|
precision={2}
|
||||||
formatter={numberFormatter}
|
formatter={numberFormatter}
|
||||||
parser={numberParser}
|
parser={numberParserAllowEmpty}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { useNavigate, useSearchParams } from "react-router-dom";
|
|||||||
import { ExtraFieldFormItem, ParsedExtras, StringifiedExtras } from "../../components/extraFields";
|
import { ExtraFieldFormItem, ParsedExtras, StringifiedExtras } from "../../components/extraFields";
|
||||||
import { useSpoolmanLocations } from "../../components/otherModels";
|
import { useSpoolmanLocations } from "../../components/otherModels";
|
||||||
import { searchMatches } from "../../utils/filtering";
|
import { searchMatches } from "../../utils/filtering";
|
||||||
import { numberFormatter, numberParser } from "../../utils/parsing";
|
import { numberFormatter, numberParser, numberParserAllowEmpty } from "../../utils/parsing";
|
||||||
import { EntityType, useGetFields } from "../../utils/queryFields";
|
import { EntityType, useGetFields } from "../../utils/queryFields";
|
||||||
import { getCurrencySymbol, useCurrency } from "../../utils/settings";
|
import { getCurrencySymbol, useCurrency } from "../../utils/settings";
|
||||||
import { createFilamentFromExternal } from "../filaments/functions";
|
import { createFilamentFromExternal } from "../filaments/functions";
|
||||||
@@ -321,7 +321,7 @@ export const SpoolEdit: React.FC<IResourceComponentsProps> = () => {
|
|||||||
addonAfter={getCurrencySymbol(undefined, currency)}
|
addonAfter={getCurrencySymbol(undefined, currency)}
|
||||||
precision={2}
|
precision={2}
|
||||||
formatter={numberFormatter}
|
formatter={numberFormatter}
|
||||||
parser={numberParser}
|
parser={numberParserAllowEmpty}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ export function formatNumberWithSpaceSeparator(input: string): string {
|
|||||||
* @param value
|
* @param value
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function numberFormatter(value: number | undefined): string {
|
export function numberFormatter(value: number | string | undefined): string {
|
||||||
|
console.log("numberformatter input: ", value);
|
||||||
const formattedValue = value
|
const formattedValue = value
|
||||||
? Number(value).toLocaleString(undefined, {
|
? Number(value).toLocaleString(undefined, {
|
||||||
useGrouping: false, // Disable thousands separator and do it manually instead so it's always spaces
|
useGrouping: false, // Disable thousands separator and do it manually instead so it's always spaces
|
||||||
@@ -45,7 +46,7 @@ export function numberFormatter(value: number | undefined): string {
|
|||||||
* @param value
|
* @param value
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function numberParser(value: string | undefined) {
|
export function numberParser(value: string | undefined): number {
|
||||||
// Convert comma to dot
|
// Convert comma to dot
|
||||||
value = value?.replace(",", ".");
|
value = value?.replace(",", ".");
|
||||||
|
|
||||||
@@ -56,6 +57,28 @@ export function numberParser(value: string | undefined) {
|
|||||||
return parseFloat(value || "0");
|
return parseFloat(value || "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number parser that supports both comma and dot as decimal separator
|
||||||
|
* Same as numberParser but allows empty values. numberParser will always return a valid number
|
||||||
|
* this one returns an empty string if the value is empty
|
||||||
|
* @param value
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function numberParserAllowEmpty(value: string | undefined): number | string {
|
||||||
|
// Convert comma to dot
|
||||||
|
value = value?.replace(",", ".");
|
||||||
|
|
||||||
|
// Remove all non-digit characters
|
||||||
|
value = value?.replace(/[^\d.-]/g, "");
|
||||||
|
|
||||||
|
if (value === "" || value === undefined) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse as float
|
||||||
|
return parseFloat(value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enrich text with links
|
* Enrich text with links
|
||||||
* @param text
|
* @param text
|
||||||
|
|||||||
Reference in New Issue
Block a user