2

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

derek
  • 9,358
  • 11
  • 53
  • 94

3 Answers3

1

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"

blueren
  • 2,730
  • 4
  • 30
  • 47
0

This for the Autoform package: https://github.com/aldeed/meteor-autoform

So unless you are using that you don't need it.

StorytellerCZ
  • 181
  • 1
  • 9
0

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.

kkkkkkk
  • 7,628
  • 2
  • 18
  • 31