Reputation: 10257
I have seen this "label" usage quite a few times in meteor simple schema. Just have no idea why do we need such a field.
const Product = new SimpleSchema({ _id: {
type: String,
label: "Product ID" } })
Thanks
Derek
Upvotes: 2
Views: 289
Reputation: 2870
If you're using just simple-schema, label will purely be for showing a more human readable/understandable error message format as @Khang answered.
If you're using autoform for generating a for based on simple-schema, the field's lable will ideally be autogenerated based on what is defined in the simple-schema. But if you want to show it in better detail, you can override it by specifically defining the label.
Eg:
userName :{
type: String,
...
}
will generate a form with an input text box. The label of this input box will by default be "User Name"
userName:{
type: String,
label: "someTextHere",
...
}
will generate an input text box. The label of this input box will now be "someTextHere" instead of "User Name"
Upvotes: 1
Reputation: 7748
IMO label is a readable name of the field, it helps the code more semantic. It also helps when debugging, for example if you have a schema field like:
// ...
appId: {
type: String,
},
// ...
Then if you do not provide the appId
value when inserting you will get this error Error: App id is required
. It could be hard to know what is wrong because SimpleSchema re-format the field name automatically. In case you provide a label field:
// ...
appId: {
type: String,
label: 'App Id of the document',
},
// ...
Then the error message will be: Error: App Id of the document is required
, it is easier to find the problem with this message.
Upvotes: 0
Reputation: 181
This for the Autoform package: https://github.com/aldeed/meteor-autoform
So unless you are using that you don't need it.
Upvotes: 0