-
Notifications
You must be signed in to change notification settings - Fork 2
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
Is this the right way ? #24
Comments
Hey @adberard! Thanks for your questions and interest. I took a look at your codesandbox and the questions in your comments, and compiled a list of answers below. Here a an updated version of your codesandbox to follow along:
It looks like the reason that you wanted to use a custom validate function was because you wanted to use a regex to validate the email, right? If that is the case, there is good news, because {
type: "text",
formType: "email",
questionId: "email",
label: "Email",
required: true,
conditionalValid: {
regex: "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}$"
}
} Within the
Here is a link to the source for It essentially boils down to: export const genericFieldProps = ({field}) => ({
_genFieldComponent: Field,
_genLabelComponent: GenericRequiredLabel,
name: field.questionId
}); Because the
You can extend the Thanks you so much for your questions, and let me know if you have any feedback as well. I have lots of ideas for features and improvements to the field type API, and look forward to hearing any suggestions you may have. |
Im the one thanking you so much for your really quick and detailed answers ! How can I set my own custom message for precise errors in field ? I need this because im planning on doing some multi-languages. How can I put my own function into validate (which would my global state for coherent dates for examples) I really look forward #23, I tryed to play around but Im not getting everything about how childrens are generated with _gencomponent ! |
I played a bit the SectionField that you started to write and it seem that validation with nested component like this isnt going to work. Even when using my own validate.js its not very simple, ive read that redux form v8 will enhance validation |
You can use the {
type: 'text',
questionId: 'Name',
conditionalValid: {
minLength: 2
},
invalidMessage: 'Must be at least two characters'
} If you're planning on using a multi-language framework, such as something like this: // the field
{
type: 'text',
questionId: 'Name',
conditionalValid: {
minLength: 2
},
invalidMessage: 'minTwoChars' // the message id from defineMessages
}
// messages
import {defineMessages} from 'react-intl';
const formMessages = defineMessages({
minTwoChars: {
id: 'formMessages.minTwoChars',
description: 'Form error message for min two characters',
defaultMessage: 'Must be at least two characters'
}
});
// field component
import {injectIntl} from 'react-intl';
const TextField = injectIntl(({intl: {formatMessage}, meta, ...props}) => (
<Input
{...props.input}
error={meta.touched && meta.invalid && formatMessage(formMessages[meta.error])}
/>
));
Not sure what you mean exactly. If you want to provide a custom validate function in addition to having const MyForm = injectGenProps(
reduxForm({
form: 'exampleForm',
onSubmit
// don't pass validate here, since it will get overridden by injectGenProps. you need to pass it above injectGenProps
})(MyFields)
);
const customValidate = (formValues) => {
// do some custom validation here, and return an errors object
};
const App = () => (
<Provider store={store}>
{/* pass a custom validate function here: */}
<MyForm fields={fields} customFieldTypes={customFieldTypes} validate={customValidate} />
</Provider>
); This is more of a last resort if you can't build the logic you need with a conditional object. There is also the option to provide your own customOperators for use in conditional object. You can find examples of conditionalOperators here:
Let me see if I can explain: The If you do want to render the
After digging around a bit, I realized that the issues we're seeing around the In the meantime, I realized you can work around it by prefixing your {
type: 'section',
label: 'Step 1',
childFields: [
{
type: 'text',
inputType: 'email',
// questionId's have been prefixed with "parent."
questionId: 'parent.email',
label: 'Email',
required: true,
conditionalValid: {
regex: '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}$'
}
},
{
type: 'text',
inputType: 'text',
questionId: 'parent.firstName',
label: 'First Name',
required: true
},
{
type: 'text',
inputType: 'text',
questionId: 'parent.secondName',
label: 'Second Name'
},
{
type: 'password',
questionId: 'parent.password',
inputType: 'password',
label: 'Password',
required: true
}
]
} |
Thank you again for your super detailled explanations !
I figured out how to use the childrenFields finally and I kept on adding components |
Wow, that
Ah, I see what you mean. We've stuck to a JSON-compatible field structure in order to make sure the field structure could be requested from a back-end, since you can't describe a function in JSON. That's also the reasoning behind the conditional object API, for things like From what I can tell, all the logic that you have in your
Are you trying to create a single checkbox field? or more like a checkbox list, where you can select multiple options? Checkbox Lists can work like a list. the value of the checkboxList can be an array, where all the const checkboxListType = ({ field, ...options }) => ({
...genericFieldProps({ field, ...options }),
_genDefaultValue: [],
component: CheckboxListField,
options: field.options
}); Single Checkboxes can be tricky in forms. Since it can only have two states, const checkboxType = ({ field, ...options }) => ({
...genericFieldProps({ field, ...options }),
_genDefaultValue: false,
_genIsFilled: ({ data, field }) => _.get(data, field.questionId) === true,
component: CheckboxField
}); As a note, if you don't use |
Thanx again for explanation, but still ended up pulling my hair off on the checkbox list. So I tryed to use _genDefaultValue, but once inside the component I cant find how to bind the list of checkbox to the value of the form. I need to use objects instead of array (because their key->value never change when you remove or insert an element). Can you help me making a basic working checkbox list component ?
Would submit a value like :
Also with an onclick event that only modify values I dont think that box would appear checked when I will need to inject Here is my latest attempt |
Here's a working example with the CheckboxField. A quick list of some changes:
|
Your help is precious, I was far to get the logic of it. I will keep on adding materials components :) |
Hello, I am trying to implement custom components for material ui and redux form.
Here is a sample where I was wondering if you could see if something from redux-form-gen was wrongly used.
I commented the parts where I have questions but if you see something that could have been done cleaner I would be really enthusiast to hear it.
https://codesandbox.io/s/yj6x97x99v
The text was updated successfully, but these errors were encountered: