improve email validation

This commit is contained in:
Peter Clement 2022-07-29 13:17:17 +01:00
parent 23dc9f6128
commit 5477ffe575
5 changed files with 41 additions and 22 deletions

View File

@ -115,6 +115,16 @@
class:is-disabled={disabled} class:is-disabled={disabled}
class:is-focused={focus} class:is-focused={focus}
> >
{#if error}
<svg
class="spectrum-Icon spectrum-Icon--sizeM spectrum-Textfield-validationIcon"
focusable="false"
aria-hidden="true"
>
<use xlink:href="#spectrum-icon-18-Alert" />
</svg>
{/if}
<input <input
{id} {id}
on:click on:click

View File

@ -8,6 +8,7 @@
import Icon from "../../Icon/Icon.svelte" import Icon from "../../Icon/Icon.svelte"
import StatusLight from "../../StatusLight/StatusLight.svelte" import StatusLight from "../../StatusLight/StatusLight.svelte"
import Detail from "../../Typography/Detail.svelte" import Detail from "../../Typography/Detail.svelte"
import Search from "./Search.svelte"
export let primaryLabel = "" export let primaryLabel = ""
export let primaryValue = null export let primaryValue = null
@ -43,17 +44,12 @@
let searchTerm = null let searchTerm = null
$: groupTitles = Object.keys(primaryOptions) $: groupTitles = Object.keys(primaryOptions)
$: filteredOptions = getFilteredOptions(
primaryOptions,
searchTerm,
getPrimaryOptionLabel
)
let iconData let iconData
/*
$: iconData = primaryOptions?.find(x => { const updateSearch = e => {
return x.name === primaryFieldText dispatch("search", e.detail)
}) }
*/
const updateValue = newValue => { const updateValue = newValue => {
if (readonly) { if (readonly) {
return return
@ -107,16 +103,6 @@
updateValue(event.target.value) updateValue(event.target.value)
} }
} }
const getFilteredOptions = (options, term, getLabel) => {
if (autocomplete && term) {
const lowerCaseTerm = term.toLowerCase()
return options.filter(option => {
return `${getLabel(option)}`.toLowerCase().includes(lowerCaseTerm)
})
}
return options
}
</script> </script>
<div <div
@ -183,6 +169,15 @@
class:auto-width={autoWidth} class:auto-width={autoWidth}
class:is-full-width={!secondaryOptions.length} class:is-full-width={!secondaryOptions.length}
> >
{#if autocomplete}
<Search
value={searchTerm}
on:change={event => updateSearch(event)}
{disabled}
placeholder="Search"
/>
{/if}
<ul class="spectrum-Menu" role="listbox"> <ul class="spectrum-Menu" role="listbox">
{#if placeholderOption} {#if placeholderOption}
<li <li

View File

@ -26,6 +26,7 @@
export let autofocus export let autofocus
export let primaryOptions = [] export let primaryOptions = []
export let secondaryOptions = [] export let secondaryOptions = []
export let searchTerm
let primaryLabel let primaryLabel
let secondaryLabel let secondaryLabel
@ -87,10 +88,15 @@
} }
return value return value
} }
const updateSearchTerm = e => {
searchTerm = e.detail
}
</script> </script>
<Field {label} {labelPosition} {error}> <Field {label} {labelPosition} {error}>
<PickerDropdown <PickerDropdown
{searchTerm}
{autocomplete} {autocomplete}
{dataCy} {dataCy}
{updateOnChange} {updateOnChange}
@ -116,6 +122,7 @@
{secondaryLabel} {secondaryLabel}
on:pickprimary={onPickPrimary} on:pickprimary={onPickPrimary}
on:picksecondary={onPickSecondary} on:picksecondary={onPickSecondary}
on:search={updateSearchTerm}
on:click on:click
on:input on:input
on:blur on:blur

View File

@ -9,6 +9,7 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import { groups, auth } from "stores/portal" import { groups, auth } from "stores/portal"
import { Constants } from "@budibase/frontend-core" import { Constants } from "@budibase/frontend-core"
import { emailValidator } from "helpers/validation"
export let showOnboardingTypeModal export let showOnboardingTypeModal
const password = Math.random().toString(36).substring(2, 22) const password = Math.random().toString(36).substring(2, 22)
@ -38,6 +39,12 @@
}, },
] ]
} }
function validateInput(email) {
if (email) {
return emailValidator(email) === true ? null : emailValidator(email)
}
}
</script> </script>
<ModalContent <ModalContent
@ -59,7 +66,7 @@
bind:inputValue={input.email} bind:inputValue={input.email}
bind:dropdownValue={input.role} bind:dropdownValue={input.role}
options={Constants.BbRoles} options={Constants.BbRoles}
error={input.error} error={validateInput(input.email)}
/> />
{/each} {/each}
<div> <div>

View File

@ -17,7 +17,7 @@
</div> </div>
{value} {value}
{:else} {:else}
<div class="text">Not Available</div> <div class="text">-</div>
{/if} {/if}
</div> </div>