forked from MapComplete/MapComplete
Fix: normalization of URLs, formatting, stabilize inputHelper
This commit is contained in:
parent
cc60d2a5fb
commit
441c4df4f6
3 changed files with 25 additions and 28 deletions
|
@ -1,26 +1,32 @@
|
|||
<script lang="ts">
|
||||
/**
|
||||
* Constructs an input helper element for the given type.
|
||||
* Note that all values are stringified
|
||||
*/
|
||||
/**
|
||||
* Constructs an input helper element for the given type.
|
||||
* Note that all values are stringified
|
||||
*/
|
||||
|
||||
import { UIEventSource } from "../../Logic/UIEventSource";
|
||||
import type { ValidatorType } from "./Validators";
|
||||
import InputHelpers from "./InputHelpers";
|
||||
import ToSvelte from "../Base/ToSvelte.svelte";
|
||||
import type { Feature } from "geojson";
|
||||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import type {ValidatorType} from "./Validators";
|
||||
import InputHelpers from "./InputHelpers";
|
||||
import ToSvelte from "../Base/ToSvelte.svelte";
|
||||
import type {Feature} from "geojson";
|
||||
import BaseUIElement from "../BaseUIElement";
|
||||
import {VariableUiElement} from "../Base/VariableUIElement";
|
||||
|
||||
export let type: ValidatorType;
|
||||
export let value: UIEventSource<string>;
|
||||
|
||||
export let feature: Feature;
|
||||
export let args: (string | number | boolean)[] = undefined;
|
||||
|
||||
let properties = {feature, args: args ?? []};
|
||||
let construct = new UIEventSource<(value, extraProperties) => BaseUIElement>(undefined)
|
||||
$: {
|
||||
construct.setData(InputHelpers.AvailableInputHelpers[type])
|
||||
}
|
||||
|
||||
export let type: ValidatorType;
|
||||
export let value: UIEventSource<string>;
|
||||
|
||||
export let feature: Feature;
|
||||
export let args: (string | number | boolean)[] = undefined;
|
||||
|
||||
let properties = { feature, args: args ?? [] };
|
||||
let construct = InputHelpers.AvailableInputHelpers[type];
|
||||
|
||||
</script>
|
||||
|
||||
{#if construct !== undefined}
|
||||
<ToSvelte construct={() => construct(value, properties)} />
|
||||
<ToSvelte construct={() => new VariableUiElement(construct.mapD(construct => construct(value, properties)))}/>
|
||||
{/if}
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
export let value: UIEventSource<string>;
|
||||
// Internal state, only copied to 'value' so that no invalid values leak outside
|
||||
let _value = new UIEventSource(value.data ?? "");
|
||||
onDestroy(value.addCallbackAndRunD(v => _value.setData(v ?? "")));
|
||||
export let type: ValidatorType;
|
||||
export let feedback: UIEventSource<Translation> | undefined = undefined;
|
||||
export let getCountry: () => string | undefined
|
||||
|
||||
let validator : Validator = Validators.get(type)
|
||||
$: {
|
||||
// The type changed -> reset some values
|
||||
|
@ -23,11 +23,6 @@
|
|||
feedback = feedback?.setData(validator?.getFeedback(_value.data, getCountry));
|
||||
}
|
||||
|
||||
onDestroy(value.addCallbackAndRun(v => {
|
||||
if(v === undefined || v === ""){
|
||||
_value.setData("")
|
||||
}
|
||||
}))
|
||||
onDestroy(_value.addCallbackAndRun(v => {
|
||||
if (validator.isValid(v, getCountry)) {
|
||||
feedback?.setData(undefined);
|
||||
|
|
|
@ -45,10 +45,6 @@ export default class UrlValidator extends Validator {
|
|||
cleaned = cleaned.substr(0, cleaned.length - 1)
|
||||
}
|
||||
|
||||
if (!str.startsWith("http") && cleaned.startsWith("https://")) {
|
||||
cleaned = cleaned.substr("https://".length)
|
||||
}
|
||||
|
||||
return cleaned
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
|
|
Loading…
Reference in a new issue