Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateRangeField usage in forms #234

Open
3 tasks
ochrstn opened this issue May 22, 2024 · 4 comments
Open
3 tasks

DateRangeField usage in forms #234

ochrstn opened this issue May 22, 2024 · 4 comments

Comments

@ochrstn
Copy link
Contributor

ochrstn commented May 22, 2024

Description

The usage of the DateRangeField inside of a form should be as easy and feature complete as any of the other build-in fields

This includes showing the error border highlighting on the field in addition to the validation message and also respecting props like isDisabled.

Link to Reproduction

https://codesandbox.io/p/sandbox/ecstatic-feistel-v7rt4g

Steps to reproduce

No response

Saas UI Version

2.8.3

Chakra UI Version

No response

Browser

No response

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

No response

Copy link

linear bot commented May 22, 2024

@Pagebakers
Copy link
Contributor

Thanks for reporting @ochrstn , i don't seem to have access to the code sandbox.

@ochrstn
Copy link
Contributor Author

ochrstn commented May 24, 2024

https://codesandbox.io/p/sandbox/ecstatic-feistel-v7rt4g

Sorry, sandbox should be public now.

@Pagebakers
Copy link
Contributor

Thanks!

I got another request for support of isInvalid and invalid styles, I'll investigate.

Here is an example with DateInput that might be useful.

import { forwardRef } from '@chakra-ui/react'
import {
  DateInput,
  DateInputProps,
  DateValue,
  parseDate,
} from '@saas-ui/date-picker'
import { createField } from '@saas-ui/forms'

interface DateFieldProps extends Omit<DateInputProps, 'value' | 'onChange'> {
  value?: string
  onChange?: (value: string) => void
}

const DateField = createField(
  forwardRef<DateFieldProps, 'input'>((props, ref) => {
    const { value: valueProp, onChange: onChangeProp, ...rest } = props

    const value =
      typeof valueProp === 'string' && valueProp !== ''
        ? parseDate(valueProp)
        : valueProp === ''
          ? undefined
          : valueProp

    const onChange = (value: DateValue | null) => {
      onChangeProp?.(value?.toString() || '')
    }

    return <DateInput ref={ref} value={value} onChange={onChange} {...rest} />
  }),
  {
    isControlled: true,
  },
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants