-
Notifications
You must be signed in to change notification settings - Fork 391
Add placeholder support for React Vanilla #1840
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
Comments
Hi @andresgutgon, thanks for the suggestion. This could definitely be added to each renderer set.
We have to think about whether it makes sense to add it to the core framework. Up until recently I would definitely have said no, as there is not much benefit of receiving a However as we recently introduced translation support it now might make sense to also provide the user a default translated placeholder as the renderer code now not only needs to look up the placeholder but potentially also translate it. |
Just was reading about it! Rework i18n support in JSON Forms core. Not sure how to i18n my forms though. Not seing documentation related with this |
I found the way the new I did a hook where I can use my i18n solution. Which in my case is react-intl. Then I use the hook on the import { useIntl } from 'react-intl'
import { UISchemaElement, Translator } from '@jsonforms/core'
import { ErrorObject } from 'ajv'
export const useTranslateError = () => {
const intl = useIntl()
return (
error: ErrorObject,
_translate: Translator,
uischema: UISchemaElement
): string => {
const params = error.params
switch(error.keyword) {
case 'required':
const fieldName = ((uischema as any)?.label || params.singProperty || '').toLowerCase()
return intl.formatMessage(
{ id: '3Fs00I', defaultMessage: 'El campo {fieldName} es obligatorio' },
{ fieldName }
)
break;
default:
return error.message
}
}
} And then I use this way: import { useTranslateError } from './useTranslateError'
const MyComponent = () => {
const translateError = useTranslateError()
return (
<JsonForms
schema={jsonSchema}
uischema={uiSchema}
config={{ hideRequiredAsterisk: true }}
data={data}
renderers={vanillaRenderers}
cells={vanillaCells}
onChange={onChange}
i18n={{ translateError }}
/>
)
} |
I'm pretty happy with the approach. The only thing I don't like so far is that errors appears when the form renders for the first time. Which is a bit weird. But I think is related with |
You can use the translation like this, however usually I would expect people to use the
You can also add |
If |
That's fine! We should probably pass the error object as an additional parameter to the
At the moment only the Angular Material renderers read the locale and use it for number formatting. In general it's a useful attribute for custom renderers in case they would like to query the locale of the form for some purpose. |
I guess this can be closed : ) |
Not yet right? The PR only added |
Is your feature request related to a problem? Please describe.
It would be great when placeholders could be defined via the ui schema and set in the respective inputs
Describe the solution you'd like
Allow for the optional attribute placeholder, e.g.
Describe alternatives you've considered
We could also think about checking for a placeholder attribute in the JSON Schema
Framework
React
RendererSet
Vanilla
Additional context
At least for Vue-Vanilla. When adding the possibility of defining a placeholder to the JSON Schema, then we could think about adding this to the JSON Forms core so any renderer set benefits from that.
This issue is a copy of this Vue issue
#1729
I guess the implementation would similar.
The text was updated successfully, but these errors were encountered: