AutoForm location

Hi,

I have a SimpleSchema with the following

location: {
  type: Object,
  index: '2dsphere',
  label: 'MongoDB specific coordinates field',
  optional:false
},
'location.type': {
    type: String,
    allowedValues: ['Point'],
    label: 'Typeof coordinates - Point'
},
'location.coordinates': {
    type: [Number],
    decimal: true,
    label: 'Array of coordinates in MongoDB style \[Lng, Lat\]'
}

Now I would llike use autoform to edit and save my location to the db

{{> afQuickField name=‘location’ value=myLocation autofocus=’’}}

How can I set the value here? i.e. how can my session variables (lat, lng) be set to the location object via autoform?
Also is it possible to hide this field but save it to the db in the background. For my user does not need to see that I will save his location.

Thx
java99

Not exactly what you were asking, but some inspiration :smiley:

SimpleSchema.messages
  lonOutOfRange: '[label] longitude should be between -90 and 90'
  latOutOfRange: '[label] latitude should be between -180 and 180'
 
LocationSchema = new SimpleSchema
  type:
    type: String,
    allowedValues: ['Point']
    defaultValue: "Point"
  coordinates:
    type: [Number]
    decimal: true
    minCount: 2
    maxCount: 2
    custom: ->
      return "lonOutOfRange" unless -90 <= @value[0] <= 90
      return "latOutOfRange" unless -180 < @value[1] <= 180

and than in the collection schema itself

 "location":
    type: LocationSchema
    index: '2dsphere'

I also tried a new approach with autoform type hidden.

'location.type': {
    type: String,
    allowedValues: ['Point'],
    label: 'Typeof coordinates - Point',
    autoform: {
      type: "hidden",
      label: false
    }
},
'location.coordinates': {
    type: [Number],
    decimal: true,
    label: 'Coordinates',
    autoform: {
      type: "hidden",
      label: false
    } // 'Array of coordinates in MongoDB style \[Lng, Lat\]'
}

In my case it works for the Point object, but does not work for coordinates which are still put on the form. I want all to be set but invisible.

you can always create your own template how it should be shown, if you dont like default behaviour.

well as I said it works all but for the array type in my schema

    {{> afQuickField name='location.type' value='Point' autofocus=''}}
    {{> afQuickField name='location.coordinates.0' value=myLng autofocus=''}}
    {{> afQuickField name='location.coordinates.1' value=myLat autofocus=''}}

So Point is hidden, but location.coordinates are shown, because maybe the “type= hidden” will not apply for all array elements. How would you do that?

well, you can create your own template how data should be shown and hardcode there any style you want.
it is not very clean solution.
I did not need to hide anything, but I was creating my own templates for material design in https://medium.com/@ShockiTV/how-i-tried-bootstrap-with-material-design-and-autoform-on-meteorjs-32333baad85f#.mo7sglnwx

Great post!

I will try a custom template solution now.

maybe just a typo: Shouldn’t be “afCheckbox_toggle” where you reference the template in your autoform sample?

Not, the afCheckbox is template name mandatory part due to being autoform and checkbox.
So you provide just the custom part in template parameter