iway1 / react-ts-form

https://react-ts-form.com
MIT License
2.01k stars 35 forks source link

Quick placeholders can't contain "//" #39

Closed florian-lefebvre closed 1 year ago

florian-lefebvre commented 1 year ago

Version Number

^1.0.10

Codesandbox/Expo snack

No response

Steps to reproduce

  1. Create a schema like the following and pass it to the form
const schema = z.object({
    url: z.string().describe('URL // https://google.com'),
})

Expected behaviour

The placeholder should be https://google.com but it's only https:. I guess this is because the separator is // and so the label is segments[0] and the placeholder segments[1].

Relevant log output

No response

iway1 commented 1 year ago

Hmm good point, yeah right now it just looks for // so would need to change it.

Wondering what a good symbol would be that would be less likely to have conflicts

florian-lefebvre commented 1 year ago

It could be useful to make it configurable in the options of createTsForm https://github.com/iway1/react-ts-form/blob/main/src/createSchemaForm.tsx#L163

iway1 commented 1 year ago

yeah good idea that way it wouldn't be a breaking change too

florian-lefebvre commented 1 year ago

But I think changing the default one would be useful, urls are often used as placeholder

iway1 commented 1 year ago

good point, we'll change the default. What about -- as the separator? Seems pretty unlikely to have conflicts

gonna have to be in v2 since it's breaking though

florian-lefebvre commented 1 year ago

LGTM

stoickeyboard commented 1 year ago

I ran into this problem as well

lucasjungdeveloper commented 1 year ago

I think the default could stay as it is if it checks for ' // ' instead of '//' Since in the URL it won't be surrounded by spaces And by doing so it woudn't be a breaking change

florian-lefebvre commented 1 year ago

Yeah sounds great! And to prevent errors we could do

const [label, ...rest] = describe.split(' // ')
const placeholder = rest.join(' // ')