TagSpaces is an offline, open source, document manager with tagging support
add lat/lng validation
stanimira9fdc61bdbc1
diff --git a/app/components/dialogs/EditEntryTagDialog.tsx b/app/components/dialogs/EditEntryTagDialog.tsxindex 481ef66ff..4521e3589 100644--- a/app/components/dialogs/EditEntryTagDialog.tsx+++ b/app/components/dialogs/EditEntryTagDialog.tsx@@ -61,7 +61,7 @@ const DateTagEditor = Pro && Pro.UI ? Pro.UI.DateTagEditor : React.Fragment;const EditEntryTagDialog = (props: Props) => {const [showAdvancedMode, setShowAdvancedMode] = useState<boolean>(false);- const [errorTag, setErrorTag] = useState<boolean>(false);+ const [errorInput, setErrorInput] = useState<Array<string>>([]);const [title, setTitle] = useState(props.selectedTag && props.selectedTag.title);@@ -71,6 +71,18 @@ const EditEntryTagDialog = (props: Props) => {handleValidation();}, [title]);+ const setError = (errorKey: string, add: boolean = true) => {+ if (add) {+ if (errorInput.length === 0) {+ setErrorInput([errorKey]);+ } else if (errorInput.indexOf(errorKey) === -1) {+ setErrorInput([...errorInput, errorKey]);+ }+ } else if (errorInput.indexOf(errorKey) > -1) {+ setErrorInput(errorInput.filter(err => err !== errorKey));+ }+ };+const isShowDatePeriodEditor = useMemo(() => {let showDatePeriodEditor = false;if (title.indexOf('-') > -1) {@@ -92,16 +104,15 @@ const EditEntryTagDialog = (props: Props) => {function handleValidation() {const tagCheck = RegExp(/^[^#/\\ [\]]{1,}$/);if (title && tagCheck.test(title)) {- setErrorTag(false);+ setError('tag', false);} else {- setErrorTag(true);+ setError('tag');}}function onConfirm() {- if (!errorTag) {+ if (errorInput.length === 0) {props.editTagForEntry(props.currentEntryPath, props.selectedTag, title);- setErrorTag(false);props.onClose();}}@@ -119,10 +130,13 @@ const EditEntryTagDialog = (props: Props) => {className={props.classes.root}style={{ overflow: AppConfig.isFirefox ? 'auto' : 'overlay' }}>- <FormControl fullWidth={true} error={errorTag}>+ <FormControl+ fullWidth={true}+ error={errorInput.some(err => err === 'tag')}+ ><TextFieldfullWidth={true}- error={errorTag}+ error={errorInput.some(err => err === 'tag')}margin="dense"name="title"autoFocus@@ -134,7 +148,7 @@ const EditEntryTagDialog = (props: Props) => {value={title}data-tid="editTagEntryDialog_input"/>- {errorTag && (+ {errorInput.some(err => err === 'tag') && (<FormHelperText>{i18n.t('core:tagTitleHelper')}</FormHelperText>)}</FormControl>@@ -144,6 +158,8 @@ const EditEntryTagDialog = (props: Props) => {onChange={setTitle}zoom={title === defaultTagLocation ? 2 : undefined}showAdvancedMode={showAdvancedMode}+ errorInput={errorInput}+ setError={setError}/>)}{isShowDatePeriodEditor && (@@ -180,7 +196,7 @@ const EditEntryTagDialog = (props: Props) => {{i18n.t('core:cancel')}</Button><Button- disabled={errorTag}+ disabled={errorInput.length > 0}onClick={onConfirm}data-tid="confirmEditTagEntryDialog"color="primary"diff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex ded7d6bb7..b2c30d945 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -556,5 +556,6 @@"exportCsv": "Export current files and folders as CSV file","lat": "Latitude","lng": "Longitude",+ "coordinatesTitleHelper": "Invalid coordinate (please use 40.123, -74.123 or 40° 7.38’, -74° 7.38’)","-": "-"}