-
-
Notifications
You must be signed in to change notification settings - Fork 245
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
Support for [email protected] #99
Comments
This is a breaking change, though! What are your thoughts on backwards compatibility? |
I want to support both at once - simply create another birdge like |
Well, there's a problem: |
would love to use simpleSchema 2. Then, we could finally use schema-based-forms in non-meteor-environements like storybook <3<3<3 I also spotted some breaking changes for my usage, but it should be fairly straight-forward. |
OK, I've started to implement this and there's one big issue with the new version internals - due to |
Well, I think I've got a solution. import SimpleSchema from 'simpl-schema';
const schema = new SimpleSchema({
// Only one type = no problem
fieldA: String, // String
// Only one type = no problem
fieldB: { // String
type: String
},
// Few types = first type
fieldC: { // String
type: SimpleSchema.oneOf(String, Number)
},
// Few types, one with type = selected one
fieldD: { // Number
type: SimpleSchema.oneOf(String, {
type: Number,
uniformsType: true
})
},
// Few types, few with type = first selected one
fieldE: { // String
type: SimpleSchema.oneOf({
type: String,
uniformsType: true
}, {
type: Number,
uniformsType: true
})
}
}); Problem: two types in schema - how to render one form with type 1 and another form with type 2? What do you think? |
I think i would not hook into the oneOf-function. If you get this schema, you can't guess which field to render. So the developer would need to specify the field either by using an explicit field in the or by specifying a component in the schema:
If nothing is specified, i would just use the first type. I think that this is an edge-case anyway. |
But I can't guess type from the field. Consider this example: import SimpleSchema from 'simpl-schema';
const schema = new SimpleSchema({
fieldA: {
type: SimpleSchema.oneOf(String, [String]),
uniforms: {
component: CustomField
}
},
fieldB: {
type: SimpleSchema.oneOf(
{type: String, min: 10},
{type: String, max: 10}
),
uniforms: {
component: TextField
}
}
}); Which one should we render now? |
In the first case, you render CustomField (fieldA) and in the second case a TextField with property min: 10. (fieldB, this definition makes little sense anyway). Or maybe i don't understand the problem? Edit: SimpleSchema.oneOf just say that any of this definitions are valid types. So the rendered field has just to fullfill this validation. If e.g. String or Number are both fine, then both a TextField and a NumberField can fullfill this validation. I hardly see a usecase for this. Maybe if you want to switch conditionally between two valid definitions and render the best form-element for that definition. But that would need to be specified in the form. |
Yeah, of course fieldA will render CustomField, but every field receive it's type (and other props). Maybe this will clarify: {
userId: {
type: SimpleSchema.oneOf({
type: String,
regEx: /^.{16}$/
}, {
type: String,
allowedValues: [
'admin',
'tester',
'guest'
]
})
}
} No matter, which field I'll render - which props should I provide? Edit: Of course, those are quite esoteric schemas, but possible ones. |
Done! I've implemented it in 1.1.0 - go and check it out. Right now, there's no support for EDIT: It will work in 1.1.1 - I forgot to export it in 1.1.0, sorry. |
Awesome, thank you! 😍 |
Love you guy <3 Logan Koester [email protected] schrieb am Mi., 28. Sep. 2016,
|
Release note.
The text was updated successfully, but these errors were encountered: