clear inputs
This commit is contained in:
parent
172d6c3c2f
commit
016e357ebd
|
@ -65,6 +65,7 @@ export function DiscussionForm ({
|
||||||
name='title'
|
name='title'
|
||||||
required
|
required
|
||||||
autoFocus
|
autoFocus
|
||||||
|
clear
|
||||||
/>
|
/>
|
||||||
<MarkdownInput
|
<MarkdownInput
|
||||||
topLevel
|
topLevel
|
||||||
|
|
|
@ -12,6 +12,7 @@ import styles from './form.module.css'
|
||||||
import Text from '../components/text'
|
import Text from '../components/text'
|
||||||
import AddIcon from '../svgs/add-fill.svg'
|
import AddIcon from '../svgs/add-fill.svg'
|
||||||
import { mdHas } from '../lib/md'
|
import { mdHas } from '../lib/md'
|
||||||
|
import CloseIcon from '../svgs/close-line.svg'
|
||||||
|
|
||||||
export function SubmitButton ({
|
export function SubmitButton ({
|
||||||
children, variant, value, onClick, ...props
|
children, variant, value, onClick, ...props
|
||||||
|
@ -129,7 +130,7 @@ function FormGroup ({ className, label, children }) {
|
||||||
|
|
||||||
function InputInner ({
|
function InputInner ({
|
||||||
prepend, append, hint, showValid, onChange, overrideValue,
|
prepend, append, hint, showValid, onChange, overrideValue,
|
||||||
innerRef, storageKeyPrefix, noForm, ...props
|
innerRef, storageKeyPrefix, noForm, clear, ...props
|
||||||
}) {
|
}) {
|
||||||
const [field, meta, helpers] = noForm ? [{}, {}, {}] : useField(props)
|
const [field, meta, helpers] = noForm ? [{}, {}, {}] : useField(props)
|
||||||
const formik = noForm ? null : useFormikContext()
|
const formik = noForm ? null : useFormikContext()
|
||||||
|
@ -152,6 +153,8 @@ function InputInner ({
|
||||||
}
|
}
|
||||||
}, [overrideValue])
|
}, [overrideValue])
|
||||||
|
|
||||||
|
const invalid = meta.touched && meta.error
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<InputGroup hasValidation>
|
<InputGroup hasValidation>
|
||||||
|
@ -179,11 +182,23 @@ function InputInner ({
|
||||||
onChange(formik, e)
|
onChange(formik, e)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
isInvalid={meta.touched && meta.error}
|
isInvalid={invalid}
|
||||||
isValid={showValid && meta.initialValue !== meta.value && meta.touched && !meta.error}
|
isValid={showValid && meta.initialValue !== meta.value && meta.touched && !meta.error}
|
||||||
/>
|
/>
|
||||||
{append && (
|
{(append || (clear && field.value)) && (
|
||||||
<InputGroup.Append>
|
<InputGroup.Append>
|
||||||
|
{(clear && field.value) &&
|
||||||
|
<Button
|
||||||
|
variant={null}
|
||||||
|
onClick={() => {
|
||||||
|
helpers.setValue('')
|
||||||
|
if (storageKey) {
|
||||||
|
localStorage.removeItem(storageKey)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className={`${styles.clearButton} ${invalid ? styles.isInvalid : ''}`}
|
||||||
|
><CloseIcon className='fill-grey' height={20} width={20} />
|
||||||
|
</Button>}
|
||||||
{append}
|
{append}
|
||||||
</InputGroup.Append>
|
</InputGroup.Append>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -10,3 +10,16 @@
|
||||||
margin-top: -1px;
|
margin-top: -1px;
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.clearButton {
|
||||||
|
background-color: var(--theme-inputBg);
|
||||||
|
border: 1px solid var(--theme-borderColor);
|
||||||
|
padding: 0rem 0.5rem;
|
||||||
|
border-left: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.clearButton.isInvalid {
|
||||||
|
border-color: #c03221;
|
||||||
|
}
|
|
@ -71,7 +71,7 @@ export default function JobForm ({ item, sub }) {
|
||||||
text: Yup.string().required('required').trim(),
|
text: Yup.string().required('required').trim(),
|
||||||
url: Yup.string()
|
url: Yup.string()
|
||||||
.or([Yup.string().email(), Yup.string().url()], 'invalid url or email')
|
.or([Yup.string().email(), Yup.string().url()], 'invalid url or email')
|
||||||
.required('Required'),
|
.required('required'),
|
||||||
maxBid: Yup.number('must be number')
|
maxBid: Yup.number('must be number')
|
||||||
.integer('must be whole').min(sub.baseCost, `must be at least ${sub.baseCost}`)
|
.integer('must be whole').min(sub.baseCost, `must be at least ${sub.baseCost}`)
|
||||||
.required('required'),
|
.required('required'),
|
||||||
|
@ -153,17 +153,20 @@ export default function JobForm ({ item, sub }) {
|
||||||
name='title'
|
name='title'
|
||||||
required
|
required
|
||||||
autoFocus
|
autoFocus
|
||||||
|
clear
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label='company'
|
label='company'
|
||||||
name='company'
|
name='company'
|
||||||
required
|
required
|
||||||
|
clear
|
||||||
/>
|
/>
|
||||||
<BForm.Row className='mr-0'>
|
<BForm.Row className='mr-0'>
|
||||||
<Col>
|
<Col>
|
||||||
<Input
|
<Input
|
||||||
label='location'
|
label='location'
|
||||||
name='location'
|
name='location'
|
||||||
|
clear
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
|
@ -183,6 +186,7 @@ export default function JobForm ({ item, sub }) {
|
||||||
label={<>how to apply <small className='text-muted ml-2'>url or email address</small></>}
|
label={<>how to apply <small className='text-muted ml-2'>url or email address</small></>}
|
||||||
name='url'
|
name='url'
|
||||||
required
|
required
|
||||||
|
clear
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label={
|
label={
|
||||||
|
|
|
@ -78,12 +78,14 @@ export function LinkForm ({ item, editThreshold }) {
|
||||||
name='title'
|
name='title'
|
||||||
overrideValue={data?.pageTitle}
|
overrideValue={data?.pageTitle}
|
||||||
required
|
required
|
||||||
|
clear
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label='url'
|
label='url'
|
||||||
name='url'
|
name='url'
|
||||||
required
|
required
|
||||||
autoFocus
|
autoFocus
|
||||||
|
clear
|
||||||
hint={editThreshold
|
hint={editThreshold
|
||||||
? <div className='text-muted font-weight-bold'><Countdown date={editThreshold} /></div>
|
? <div className='text-muted font-weight-bold'><Countdown date={editThreshold} /></div>
|
||||||
: null}
|
: null}
|
||||||
|
|
Loading…
Reference in New Issue